Angular UI-Router 多个视图

2023-12-19

我正在使用有角度的 UI 路由器。我的路线配置中有以下内容

.config(function config($stateProvider) {
  $stateProvider.state('newsFeedView', {
      url: '/newsFeed',
      controller: 'newsFeedController',
      templateUrl: '../src/app/bulletinBoard/views/newsFeed.part.html',
      data: {
        pageTitle: 'News Feed'
      }
    })
    .state('tradeFeedView', {
      url: '/tradeFeed',
      controller: 'tradeFeedController',
      templateUrl: '../src/app/bulletinBoard/views/tradeFeed.part.html',
      data: {
        pageTitle: 'Trade Feed'
      }
    })
    .state('bulletinBoard', {
      url: '/bulletinBoard',
      views: {
        'tradeFeed': {
          url: "",
          controller: 'tradeFeedController',
          templateUrl: '../src/app/bulletinBoard/views/tradeFeed.part.html'
        },
        'newsFeed': {
          url: "",
          controller: 'newsFeedController',
          templateUrl: '../src/app/bulletinBoard/views/newsFeed.part.html'
        }
      },
      templateUrl: '../src/app/bulletinBoard/views/bulletinBoard.part.html'
    });
})

在我的索引页面中,我只是使用以下方式调用视图:

<div class="container" ui-view></div>

在我的BulletinBoard.html 中我想要一个嵌套视图:

<div ui-view="tradeFeed"></div>
<div ui-view="newsFeed"></div>

对于 /newsFeed 页面和 /tradeFeed 页面,这工作得很好,但对于公告板,我在页面上看不到任何内容。我哪里出错了?


我发现官方 GitHub wiki 上的示例非常不直观。这是一个更好的:

https://scotch.io/tutorials/angular-routing-using-ui-router https://scotch.io/tutorials/angular-routing-using-ui-router

例如:

...

.state('bulletinBoard', {
    url: '/bulletinBoard',
    views: {

        // the main template will be placed here (relatively named)
        '': { templateUrl: '../src/app/bulletinBoard/views/bulletinBoard.part.html' },

        // the child views will be defined here (absolutely named)
        'tradeFeed@bulletinBoard': { template: ..... },

        // another child view
        'newsFeed@bulletinBoard': { 
            templateUrl: ......
        }
    }

});

每个视图属性的语法是viewName@stateName.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Angular UI-Router 多个视图 的相关文章

随机推荐