【问题标题】:AngularJS UI Router nested states are not workingAngularJS UI路由器嵌套状态不起作用
【发布时间】:2017-10-05 02:22:59
【问题描述】:

我正在尝试在 UI-Router 中设置嵌套状态。但没有运气。我不断收到以下错误。

Uncaught Error: [$injector:modulerr] Failed to instantiate module AdminPortal due to:
Error: Cannot combine: component|bindings|componentProvider with: templateProvider|templateUrl|template|notify|async|controller|controllerProvider|controllerAs|resolveAs in stateview: '$default@auth.portal.dashboard'

这是我的路线,当我去的时候:

$stateProvider
        .state('auth.portal', {
            templateUrl: '/admin/dist/templates/portal.tpl.html'
        })
        .state('auth.portal.dashboard', {
            url: '/dashboard',
            component: 'dashboardComponent',
            templateUrl: '/admin/dist/templates/dashboard.tpl.html'
        });

portal.tpl.html

<h1>Portal</h1>
<ui-view></ui-view>

基本上我想加载 portal.tpl.html 并将该文档中的 ui-view 用于 dashboard.tpl.html .

我已经在 Stack Overflow 上查看了GitHub Docsthis Plunkr 和其他一些问题,但仍然无法正常工作。

【问题讨论】:

  • 我可以看到错误清楚地说明了这一点。您应该从状态定义中删除 templateUrl 属性,这对我来说更有意义.. 因为组件将处理 URL

标签: javascript angularjs angular-ui-router angular-components


【解决方案1】:

您现在使用组件时似乎不需要在 State 路由器中指定 tempale。组件应该有模板定义。这是更多信息的链接 https://ui-router.github.io/guide/ng1/route-to-component

【讨论】:

  • 我认为在哪里定义它并不重要,因为通常我在组件中具有与您建议的完全相同的 templateUrl。但是当我在组件中定义它时,它显然有效!谢谢!
猜你喜欢
  • 2016-10-19
  • 1970-01-01
  • 2016-06-17
  • 2015-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-11
  • 2015-11-25
相关资源
最近更新 更多