尝试使用Angular UI-Router链接到子URL(非常新的)
我有: -
app.config(function($stateProvider, $urlRouterProvider, $locationProvider){
$urlRouterProvider.otherwise("/products")
$stateProvider
.state('products', {
url: "/products",
templateUrl: "products.html",
})
.state('products.edit', {
url: "/:id",
templateUrl: "products.edit.html",
controller: function ($scope, $stateParams) {
$scope.id = $stateParams.id;
console.log($stateParams.id)
}
})
.state('customers', {
url: "/customers",
templateUrl: "customers.html",
});
//$locationProvider.html5Mode(true);
});
我可以导航到产品和客户,但不能导航到products.edit状态。
这是PLUNKER
答案 0 :(得分:2)
因为products.edit
是products
的子状态,所以前者的视图将嵌入到后者的视图中。因此,在products.html
中,您需要添加<ui-view>
,其中ui-router
将放置子视图。像这样:
<div>
<h4>Products Page</h4>
<ui-view></ui-view>
</div>
请参阅此updated plunker。