AngularJS的ngroute 路由传参

转自:出处



    
    
    
    
    




    


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

    app.config(['$routeProvider', function ($routeProvider) {
        $routeProvider
            .when('/div1', {
                template: '

这是div1{{text}}

', controller: 'div1Controller' }) .when('/div2', { template: '

这是div2{{text}}

', controller: 'div2Controller' }) .when('/div3', { template: '

这是div3{{text}}

', controller: 'div3Controller' }) .when('/content/:id', { template: '

这是content{{id}}

', controller: 'div4Controller' }) .otherwise({ redirectTo: '/div1' }); }]); app.controller('div1Controller', function ($scope) { $scope.text = 'phonegap中文网div1Controller'; }) app.controller('div2Controller', function ($scope) { $scope.text = 'phonegap中文网div2Controller'; }) app.controller('div3Controller', function ($scope) { $scope.text = 'phonegap中文网div3Controller'; }) app.controller('div4Controller', function ($scope, $routeParams, $location) { if ($routeParams.id==0) { $location.path('/div1');//进行页面跳转 } console.log($routeParams); $scope.id = $routeParams.id; $scope.text = 'phonegap中文网div3Controller'; })


你可能感兴趣的:(Angularjs)