码迷,mamicode.com
首页 > Web开发 > 详细

angularjs路由简单实现

时间:2016-06-16 18:06:56      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

1. [代码]mainApp.js用于控制路由分配和模板的js     

/**
 * mainApp module
 */
var mainApp = angular.module(‘mainApp‘, [ ‘ngRoute‘, ‘ngResource‘ ]);
 
mainApp.config([ ‘$routeProvider‘, function($routeProvider) {
 
    $routeProvider.when(‘/add.do‘, {
        templateUrl : ‘insurance_add.html‘,
        controller : ‘InsuranceAddController‘
    });
     
    $routeProvider.when(‘/list.do‘, {
        templateUrl : ‘insurance_list.html‘,
        controller : ‘InsuranceListController‘
    });
 
    $routeProvider.otherwise({
        redirectTo : ‘/list.do‘
    });
 
} ]);

2. [代码]InsuranceAddController.js用于处理页面跳转的js     

/**
 *  Controller
 */
 
mainApp.controller(‘InsuranceAddController‘, [‘$scope‘‘$location‘function($scope, $location) {
 
    $scope.gotoList = function() {
        $location.path(‘/list.do‘);
    };
  
}]);

3. [代码]InsuranceListController.js另外一个处理列表的控制器     

/**
 * Controller
 */
 
mainApp.controller(‘InsuranceListController‘, [‘$scope‘‘$location‘function($scope, $location) {
      
    $scope.gotoAdd = function() {
        $location.path(‘/add.do‘);
    };
   
}]);

angularjs路由简单实现

标签:

原文地址:http://www.cnblogs.com/JSWBK/p/5591588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!