如何在多页的角度js路由器中进行内部ui-view

时间:2018-06-10 08:14:52

标签: angularjs angular-ui-router

我有以下页面:

  <div class="header"></div>
       <ui-view></ui-view>
  <div class="footer"></div>

我的页面配置为:

 .state('reports', {
        url: "/",
        templateUrl: "src/r.php",
        controller: 'RController',
        controllerAs: 'R'
       })
       .state('data', {
             url: "/data/:dataID",
             templateUrl: "src/data.php",
             controller: 'DataController',
             controllerAs: 'vm',
        });

现在我想添加另一个名为“test”的页面。 ,但这个页面我想使用内部ui-view。所以页面看起来像:

<div class="testPage">
   <div ui-view="users"></ui-view>
   <div ui-view="another"></ui-view>
</div>

我的问题是如何将其添加到路由中 我尝试了以下但我得到了空洞的观点:

 .state('data', {
                url: "/data",
                templateUrl: "src/data.php",
               //controller: 'DataController', // i tried also with and without this
                //controllerAs: 'Data',// i tried also with and without this
                views: {
                     'users': {
                       templateUrl: 'src/data/users.php',
                       controller: 'UsersController',
                       controllerAs: 'vm',
                     }
              } 

1 个答案:

答案 0 :(得分:0)

我认为在状态声明中,templateUrl应引用带有名为'users'的视图的页面

.state('data', {
                url: "/data",
                templateUrl: "src/data.php",
                views: {
                     'users': {
                       templateUrl: 'src/data/users.php', // This should be 'test' page or some other page with a view named 'users'
                       controller: 'UsersController',
                       controllerAs: 'vm',
                     }
              }