I have the following controllers, and I want the template of the CategoryController to be shown on all pages (ie with all other views). the app displays all categories with this controller, when you click a category it shows all books in that category, then when you click a book it shows the books details. I want the categories to be always shown, can this be done ng-include?
我有以下控制器,我希望CategoryController的模板显示在所有页面上(即所有其他视图)。该应用程序显示具有此控制器的所有类别,当您单击某个类别时,它会显示该类别中的所有书籍,然后当您单击书籍时,它会显示书籍详细信息。我希望始终显示类别,这可以通过ng-include进行吗?
app.config(function ($routeProvider) {
$routeProvider
.when('/books', {
controller: 'BookshelfController',
templateUrl: 'views/bookshelf.html'
})
.when('/books/:bookId', {
controller: 'BookController',
templateUrl: 'views/book.html'
})
.when('/categories', {
controller: 'CategoryController',
templateUrl: 'views/categories.html'
})
.when('/categories/:categoryId', {
controller: 'BookCategoryController',
templateUrl: 'views/booksincategory.html'
})
.otherwise({
redirectTo: '/books'
});
});
html
HTML
<div class="main">
<div class="container">
<div ng-view></div>
</div>
</div>
1 个解决方案
#1
0
As @Hadi says, use angular-ui-router, or why not just place the controller directly over the view when it should be shown on every page, anyway?
正如@Hadi所说,使用angular-ui-router,或者为什么不将控制器直接放在视图上,无论如何应该在每个页面上显示?
<div class="main">
<div class="container">
<div ng-controller="CategoryController"></div>
<div ng-view></div>
</div>
</div>
#1
0
As @Hadi says, use angular-ui-router, or why not just place the controller directly over the view when it should be shown on every page, anyway?
正如@Hadi所说,使用angular-ui-router,或者为什么不将控制器直接放在视图上,无论如何应该在每个页面上显示?
<div class="main">
<div class="container">
<div ng-controller="CategoryController"></div>
<div ng-view></div>
</div>
</div>