首先,你可以使用角UI Angular-UI/UI-Router
主要思想在裏面是有狀態的,因爲你有單頁的應用程序,一切都只是說明誰在一個地方使。沒有刷新什麼。
集成時它可以創建
$stateProvider
.state("bookPreview", {
url: "/book/:id/:itemId",
controller: "BookPreviewCtrl",
templateUrl: 'sb/add-cpe-template.tpl.html'
});
在你的HTML,你可以做以下的事情:
<button ng-click="view(item.bookId, item.id)">Chapter {{item.id}}</button>
或類似的東西,你可以分配超鏈接NG單擊爲好。
的Java腳本視圖功能是:(但在此之前,你必須注入$
controller("BookSelectionCtrl",function($scope,$state){
//this will rewrite the url , go to the state and load the template(view).
$scope.view=function(bookId,itemId){
$state.go("bookPreview",{id:bookId,itemId:itemId}) //there is a third object representing options, which are optional and you can check them on doc site
}
})
controller("BookPreviewCtrl",function($scope,$stateParams){
//in this new ctrl of the new view you can now do what ever you want with these params
$scope.bookId = $stateParams.id;
$scope.itemId = $stateParams.itemId;
})
來源
2014-06-13 11:55:31
Tek
看起來不錯,但我怎麼能提取特定的控制器代碼? – dubadub
我沒有得到你的問題,你指的是什麼代碼? –
我的意思是'MainCtrl'中的所有代碼。可能是創建提供程序,將生成所有指令? – dubadub