AngularJs:ui.router 未加载 Controller

标签 angularjs angular-ui-router

我尝试将 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/

相关文章:

javascript - 使用 javascript 使用排序函数而不使用 lambda 函数

node.js - 点击提交时无法检查为空或为null

javascript - Angular ui.router 默认页眉页脚

angularjs - 改变状态什么也不做

javascript - TypeScript 构建错误 : Property does not exist on type 'IStateParamsService'

javascript - 如何为多个模板拥有一个 Controller 的多个实例

AngularJS DRY Controller 结构

javascript - 为什么 Or 不能在 angularJs ng-pattern 中工作?

javascript - Firebase:从另一个对象检索数据

javascript - 指令内的范围变量未显示值