我尝试将 AngularJs 与 ui.router 一起使用,但遇到了麻烦。
此示例有三种状态:index、template 和 template.show
$stateProvider
.state('/', {
url: '',
template: '<a ui-sref="template">GoTo Template Index</a>'
})
.state('template', {
url: 'template',
templateUrl: 'template_index.html',
controller: 'TemplateCtrl'
})
.state('template.show', {
url: '/{templateId:[0-9]+}',
templateUrl: 'template_show.html',
controller: 'TemplateShowCtrl'
})
请参阅骗子:http://plnkr.co/edit/prluQs9vXeJw9IVi2JYW?p=info
但只有两个第一状态有效。状态“template.show”正在更改,正在加载模板,但不执行 TemplateShowCtrl 且不更新 ui-view 到新模板。
您可以看到screenshot
最佳答案
任何子状态都需要在其父状态中存在后续的 ui-view
指令,以便它知道在哪里插入 html。目前,template_index.html
标记中不存在该标记。
它应该看起来类似于:
<ul>
<li ng-repeat="t in templates">
<a ui-sref="template.show({templateId:t.id})" href='#'>
{{t.name}}
</a>
</li>
</ul>
<!-- target element -->
<ui-view></ui-view>
关于AngularJs:ui.router 未加载 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28206622/