美文网首页我爱编程
AngularJS ng-route &&&a

AngularJS ng-route &&&a

作者: 还是老徐ooo | 来源:发表于2018-04-15 18:18 被阅读20次

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

app.config(['$routeProvider',function($routeProvider){

$routeProvider.when('/a',{template:'

ng-view html

'})

.when('/b',{template:'

ng-view css

'})

.when('/c',{

templateUrl:'./list.html',     //templateUrl:' 引入文件.html'

controller:"listCTRL"        //数据所属控制器

                })

.otherwise({redirectTo:'/'});

}]);

app.controller('actrl',['$scope',function($scope){

$scope.hello ='hello world';

}]);

app.controller('listCTRL',['$scope',function($scope){

//传入数据

$scope.list = ["新 浪",'搜 狐','凤凰网','头 条','腾 讯','今日热点',];

}]);

//$routeParams服务,它可以让你获取当前路由的参数(它实际上是$location.search()和path()的结合体)。

app.controller('listCTRL',['$scope','$routeParams',function($scope,$routeParams){

//传入数据

        $scope.list = ["新 浪",'搜 狐','凤凰网','头 条','腾 讯','今日热点',];

//        http://localhost:63342/%E5%AD%A6%E4%B9%A0Angular/html/ag04-ngrout.html#/c?name=xjh&age=33

//        {name: "xjh", age: "33"}

        console.log($routeParams);

}]);

相关文章

网友评论

    本文标题:AngularJS ng-route &&&a

    本文链接:https://www.haomeiwen.com/subject/dqfjkftx.html