首先,你可以使用角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