angularjs路由简单实现

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');
    };
   
}]);
原文地址:https://www.cnblogs.com/JSWBK/p/5591588.html