简体   繁体   English

AngularJS UI-Router导航到子URL

[英]AngularJS UI-Router navigate to a child URL

Trying to link to a child URL using Angular UI-Router (very new to this) 尝试使用Angular UI-Router链接到子URL(这是新功能)

I have:- 我有:-

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);         
});

I can navigate to products and customers, but not the products.edit state. 我可以导航到产品和客户,但不能导航到products.edit状态。

Here is a PLUNKER 这是一个PLUNKER

Because products.edit is the child state of products , the view of the former is to be embedded into the view of the latter. 由于products.edit是的子状态products ,前者的观点是被嵌入到后者的观点。 So in products.html , you need to include a <ui-view> where ui-router will place the child view. 因此,在products.html ,您需要包括<ui-view> ,其中ui-router将放置子视图。 Like this: 像这样:

<div>
 <h4>Products Page</h4>
 <ui-view></ui-view>
</div>

See this updated plunker . 请参阅此更新的插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM