angularJS中router的使用指南
程序员文章站
2022-07-08 19:34:37
这几天看了angularjs和backbone,大看了解了knockout和emberjs,刚刚上网看到了一个angular的router的demo,现在顺便记下来
复制...
这几天看了angularjs和backbone,大看了解了knockout和emberjs,刚刚上网看到了一个angular的router的demo,现在顺便记下来
<!---
demo_index.html
-->
<!doctype html>
<head>
<meta charset="utf-8">
<title>route</title>
</head><br>//这个重要是做ie的兼容,发现不管用,ie坑爹,你懂的
<body ng-app="routeapp" class="ng-app:routeapp" id="routeapp">
<h1>route demo index</h1>
<script src=">
<script src=">
<div ng-view></div>
<script src=">
<script>
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;
});
</script>
</body>
</html>
//list.html
运行下面代码
<hr/>
<h3>route : list.html</h3>
<ul>
<li ng-repeat="id in [1, 2, 3 ]">
<a href="#/list/{{ id }}"> id{{ id }}</a>
</li>
</ul>
//detail.html
运行下面代码
<hr/>
<h3>route <span style="color: red;">{{id}}</span>: detail.html </h3>
代码就这些了,希望小伙伴们能够喜欢。
上一篇: angularJS 入门基础