angularJS中router的使用指南
這幾天看了angularjs和backbone,大看了解了knockout和emberjs,剛剛上網(wǎng)看到了一個(gè)angular的router的demo,現(xiàn)在順便記下來
<!---
DEMO_INDEX.html
-->
<!doctype html>
<head>
<meta charset="utf-8">
<title>route</title>
</head><br>//這個(gè)重要是做IE的兼容,發(fā)現(xiàn)不管用,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="http://localhost:81/js/angular.min.js"></script>
<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
運(yùn)行下面代碼
<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
運(yùn)行下面代碼
<hr/>
<h3>Route <span style="color: red;">{{id}}</span>: detail.html </h3>
代碼就這些了,希望小伙伴們能夠喜歡。
相關(guān)文章
解決angular雙向綁定無效果,ng-model不能正常顯示的問題
今天小編就為大家分享一篇解決angular雙向綁定無效果,ng-model不能正常顯示的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10angular基于ng-alain定義自己的select組件示例
這篇文章主要介紹了angular基于ng-alain定義自己的select組件示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02Angular如何在應(yīng)用初始化時(shí)運(yùn)行代碼詳解
這篇文章主要給大家介紹了關(guān)于Angular如何在應(yīng)用初始化時(shí)運(yùn)行代碼的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06Bootstrap + AngularJS 實(shí)現(xiàn)簡(jiǎn)單的數(shù)據(jù)過濾字符查找功能
這篇文章主要介紹了 Bootstrap + AngularJS 實(shí)現(xiàn)簡(jiǎn)單的數(shù)據(jù)過濾字符查找功能,代碼簡(jiǎn)單易懂,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2017-07-07angularjs2 ng2 密碼隱藏顯示的實(shí)例代碼
本篇文章主要介紹了angularjs2 ng2 密碼隱藏顯示的實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08Angular angular-file-upload文件上傳的示例代碼
這篇文章主要介紹了Angular angular-file-upload文件上傳的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08angularJs自定義過濾器實(shí)現(xiàn)手機(jī)號(hào)信息隱藏的方法
今天小編就為大家分享一篇angularJs自定義過濾器實(shí)現(xiàn)手機(jī)號(hào)信息隱藏的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10