AngularJS UI-Router导航到子URL

时间:2022-04-16 19:38:37

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

1 个解决方案

#1


2  

Because products.edit is the child state of products, the view of the former is to be embedded into the view of the latter. So in products.html, you need to include a <ui-view> where ui-router will place the child view. Like this:

因为products.edit是产品的子状态,所以前者的视图将嵌入到后者的视图中。所以在products.html中,你需要包含一个 ,其中ui-router将放置子视图。喜欢这个:

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

See this updated plunker.

查看此更新的plunker。

#1


2  

Because products.edit is the child state of products, the view of the former is to be embedded into the view of the latter. So in products.html, you need to include a <ui-view> where ui-router will place the child view. Like this:

因为products.edit是产品的子状态,所以前者的视图将嵌入到后者的视图中。所以在products.html中,你需要包含一个 ,其中ui-router将放置子视图。喜欢这个:

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

See this updated plunker.

查看此更新的plunker。