[英]Partial views in AngularJS
我是Angular的新手,非常感謝任何建議。 基本上,我有一對多的關系 - 一個Category
有幾個Product
,我有布局頁面,我在其中呈現不同的部分視圖:
<div class="mainContent">
<ng-view></ng-view>
</div>
我的第一個視圖顯示了類別列表,當單擊其中一個時,我會顯示第二個視圖,它分為兩部分:類別列表和特定類別的產品列表,示意圖如下所示:
我的問題是我無法弄清楚如何使用另一個部分產品列表,因為想要將它們保存在單獨的.html中。
我配置了路線:
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/category', {
templateUrl: 'category.html',
controller: 'categoryController as catCtrl'
})
.when('/category/:id', {
templateUrl: 'categoryDetail.html',
controller: 'categoryDetailController as catDetailCtrl'
})
.when('/product/:category_id', {
templateUrl: 'product.html',
controller: 'productController as productCtrl'
})
.otherwise({
redirectTo: "/category"
});
});
和控制器:
app.controller("categoryController", function($http)
{
var vm = this;
vm.categories = somedata;
});
app.controller("categoryDetailController", function($http, $routeParams)
{
var vm = this;
vm.category = somedata;//current category from REST api, using $routeParams.id
});
app.controller("productController", function($http, $routeParams)
{
var vm = this;
vm.products = somedata;//product list of current category using $routeParams.category_id
});
所以在我的第一個視圖 - category.html
,我有hrefs的類別列表:
<a href="#/category/{{category.id}}">
在第二個 categoryDetail.html
,我再次列出類別,但使用另一個hrefs:
<a href="#/product/{{category.id}}">
在最后一個視圖 - product.html
我列出了產品。
直到現在,當我點擊categoryDetail.html中的categoryDetail.html
我的product.html
在布局的mainContent
div中呈現,而不是 - 我需要它在categoryDetail.html
呈現為內部部分。 我試圖再次使用<ng-view>
,但這似乎不正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.