angularjs - 在 Angular ui-router 子模板中不起作用

标签 angularjs angular-ui-router angular-ui

我已注册状态 test带着 child .child1 ,这里 parent (test)工作正常。当我导航到状态 test.child1 URL 更改为 #/test/child1但 View 保持不变,子模板不起作用

angular.module('uiRouterSample.contacts', [
  'ui.router'
])

.config(
  [          '$stateProvider', '$urlRouterProvider',
    function ($stateProvider,   $urlRouterProvider) {
      $stateProvider
      .state('test',{
            url:'/test',            
            template:'<a ui-sref="test">Parent</a> -> <a ui-sref=".child1">child1</a>',
            controller: ['$scope', '$state', 'contacts', 'utils',
              function (  $scope,   $state,   contacts,   utils) {
              }]
        }).state('test.child1',{
            url:'/child1',            
            template:'Child template working fine'
        })
    }
  ]
)        

最佳答案

您需要一个 ui-view父状态(测试状态)模板中的指令:

  template:'<div ui-view/> <a ui-sref="test">Parent</a>  <a ui-sref=".child1">child1</a></div>',

基本上,每当您在 ui-router 中有一个状态将具有子状态时,该子状态的直接父级也必须具有 ui-view其模板中的指令。

关于angularjs - 在 Angular ui-router 子模板中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25382246/

相关文章:

angularjs - 对底层数组进行更改时,ng-repeat 不会重新排序

Angularjs 和 UI-Select : how to select an option from code

javascript - angularjs - 选择的 ng-model 索引

javascript - 使用 ngDraggable (AngularJS) 的未定义触摸

Angularjs $state.go 在新标签页中打开链接

javascript - 阻止用户登录后导航到某些网址 - angular-ui-router

angularjs - 当 $state.go 调用 $stateChangeStart 时,Angular 1.4.1 UI 路由器 10 $digest() 迭代

angularjs - 具有禁用行的 ng-options

javascript ajax没有按时更新变量

angularjs - Angular UI 路由器,如何从 Controller 获取当前状态的祖先列表?