Angular:嵌套状态在UI-Router

时间:2016-06-03 14:27:10

标签: angularjs routing angular-ui-router multi-level

多级嵌套在ui-router中不起作用。我添加了" ui-view"在名为" tpl.hello.html"的模板中这是国家" home.hello"的模板。这个" home.hello"国家是一个儿童国家"家庭"州。之后我在stateprovider中添加了以下状态:

 .state('home.hello.test', {
      url: '/test',
      templateUrl: 'tpl.hellonested.html'
 })

但是这个" home.hello.test"内部没有加载" home.hello"状态。

以下是plunkr

2 个答案:

答案 0 :(得分:0)

我认为你对ui-router中的嵌套有错误的想法。 子状态加载父状态,而不是其他方式。

在您自己的plunkr中,如果单击链接测试,您可以看到父状态(home.hello)已加载到子状态(home.hello.test)。

<div ui-view></div>只定义父视图中子视图的位置。如果将它放在父视图的顶部,子视图将加载在父视图的顶部,如果将其放在底部,它将加载到底部。

有关此link

的良好文档

希望这会对你有所帮助。

答案 1 :(得分:0)

我没有看到任何问题,根据你的plunkr,你的路线是

-Home
   *Home.Home1
      >Home.Home1.Test
   *Home.Home2

因此,如果你去“Home.Home1”,它将 NOT 加载“Home.Home1.Test”< / strong>下, 但如果你加载“Home.Home1.Test”,它还会加载其所有父状态。这是一个Introduction to Deployment Synchronizer(只是修改了一下)。