angular js ng-route 路由简单实例

angular js ng-route 路由简单实例:

注意:必须引入angular-route.js

index.html:


  
    
    My HTML File
    
      
      
    
    
      
  
  
     

allPerson.html

personDetail.html

personId{{personId}}
app.js

注意:依赖注入 ngRoute 模块

otherwise() 定义的找不到路径时跳转的路由

$routeParams:参数传递

var app = angular.module('myApp',['ngRoute']);

function personDetailCtrl($scope,$routeParams){
    $scope.personId = $routeParams.personId;
}

app.config(['$routeProvider', function($routeProvider) {
        $routeProvider
           .when('/allPerson',
            {
                templateUrl: 'html/allPerson.html'
            })
            .when('/detail/:personId',
            {
                templateUrl: 'html/personDetail.html',
                controller:personDetailCtrl
            }).otherwise(
            {
                 redirectTo: '/allPerson'
            });
    }]);




你可能感兴趣的:(javaScript,angular,js)