汽车vr网
您的当前位置:首页angularJS中router的使用指南_AngularJS

angularJS中router的使用指南_AngularJS

来源:汽车vr网


这几天看了angularjs和backbone,大看了解了knockout和emberjs,刚刚上网看到了一个angular的router的demo,现在顺便记下来

代码如下:
DEMO_INDEX.html
-->



route

//这个重要是做IE的兼容,发现不管用,IE坑爹,你懂的

Route Demo index


http://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2pre/html5shiv.js">
http://cdnjs.cloudflare.com/ajax/libs/json2/20121008/json2.js">

http://localhost:81/js/angular.min.js">

var routeApp = angular.module('routeApp',[]);
routeApp.config(['$routeProvider',function ($routeProvider) {
$routeProvider
.when('/list', {
templateUrl: 'list.html',
controller: 'RouteListCtl'
})
.when('/list/:id', {
templateUrl: 'detail.html',
controller: 'RouteDetailCtl'
})
.otherwise({
redirectTo: '/list'
});
}]);
//controller
routeApp.controller('RouteListCtl',function($scope) {
});
routeApp.controller('RouteDetailCtl',function($scope, $routeParams) {
$scope.id = $routeParams.id;
});



  

//list.html

运行下面代码

代码如下:



Route : List.html




  • ID{{ id }}


  • //detail.html

    运行下面代码

    代码如下:



    Route {{id}}: detail.html


    代码就这些了,希望小伙伴们能够喜欢。

    显示全文