简体   繁体   English

我无法使有角度的ui路由器嵌套状态正常工作。 里面的代码

[英]I can't get my angular ui-router nested states to work. Code inside

I literally tried anything at this point, but I am still learning and can't get this to work. 在这一点上,我确实尝试了任何方法,但我仍在学习中,无法使它起作用。 https://plnkr.co/edit/FrNChlSwHYDbapr7gFQH?p=preview https://plnkr.co/edit/FrNChlSwHYDbapr7gFQH?p=preview

<a class="collection-item" 
    ng-repeat="task in tasks"
    ui-sref="todo.detail({ todoID: task.todoID })">
    {{ task.text }}
</a>

What I am trying to do, is routing to /todo/1, /todo/2 and so on from the "todo"-view, but I seem to have a problem with the $stateParams. 我正在尝试从“ todo”视图路由到/ todo / 1,/ todo / 2等,但是$ stateParams似乎有问题。 It'd be nice if you guys could help me out and show me where my problem is :). 如果你们能帮助我并告诉我问题出在哪里,那就太好了:)。

Assuming each task in your array of tasks has an ID you want to then navigate to you're going to need something along the lines of: 假设任务数组中的每个任务都有一个ID ,然后要导航到该ID ,则需要遵循以下内容:

<a class="collection-item" 
    ng-repeat="task in tasks"
    ng-href="#todo/{{ task.todoID }}">
    {{ task.text }}
</a>

You'll then need the /todo/:toDoId or something similar set up in your routes. 然后,您需要/todo/:toDoId或在路由中设置的类似设置。

You have not defined todoID in your tasks items. 您尚未在tasks项中定义todoID

This works: https://plnkr.co/edit/Wk33w2eRfpz7UZNNZzFs?p=preview 这有效: https : //plnkr.co/edit/Wk33w2eRfpz7UZNNZzFs?p=preview

In addition to adding an id field to your task objects you will need to put a <section ui-view></section> in your todo.html file. 除了向任务对象添加id字段外,您还需要在todo.html文件中放入<section ui-view></section> This is how nested states work. 这就是嵌套状态的工作方式。 You can use an href as Oliver mentioned or stick to the sref. 您可以使用Oliver提到的href或坚持使用ref。 I've forked your plunk here as an example. 我在这里分叉了您的朋克。

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

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