简体   繁体   English

angularjs-ui-router多个嵌套视图

[英]angularjs - ui-router multiple nested views

Trying to figure out multiple nested views concept and don't seem to understand what I'm doing wrong. 试图弄清楚多个嵌套视图的概念,并且似乎不明白我在做什么错。

app.js routing config : app.js路由配置:

.config(function($stateProvider, $locationProvider, $urlRouterProvider) {
    'ngInject';

    $stateProvider.state('home', {
         url: '/',
         templateUrl: 'tpls/views/welcome.html'
    })
    .state('feeds', {
        url: '/feeds',
        views: {
            'main': {
                templateUrl: 'tpls/views/main.html'
            },
            'siderbar@feeds' : {
                templateUrl: 'tpls/views/sidebar.html',
                controller: 'MyCtrl',
                controllerAs : 'main'
            },
            'mainfeed@feeds': {
                templateUrl: 'tpls/views/mainfeed.html',
                controller: 'MyCtrl',
                controllerAs : 'main'
            }
        }
    });
    $urlRouterProvider.otherwise('/');
    $locationProvider.html5Mode(true);
});

HTMLs: HTMLS:

on

index.html
I have an an empty directive <div ui-view></div> 我有一个空指令<div ui-view></div>

and this is main.html : 这是main.html

 <div class="row"> <div class="col-md-4 no-float sidebar"> <div ui-view="sidebar"></div> </div> <div class="col-md-8 no-float"> <div ui-view="mainfeed"></div> </div> </div> 

My views arent rendering. 我的观点没有渲染。 When in /feeds I only see the background. /feeds我只会看到背景。 Can you please help me spot the problem? 你能帮我发现问题吗? Went over the github documentation and still couldn't infer the solution. 浏览了github文档,但仍然无法推断解决方案。 Thanks! 谢谢!

Make sure that base page index.html should have named view main . 确保基本页面index.html应该具有名为main视图。

<div ui-view="main"></div>

If main named view isn't there then, you could have '' in your base view of feeds like below. 如果main命名视图不存在,则可以在feeds的基本view '' ,如下所示。

Code

.state('feeds', {
    url: '/feeds',
    views: {
        //used blank to target unnamed `ui-view` placed on html
        '': {
            templateUrl: 'tpls/views/main.html'
        },
        'siderbar@feeds' : {
            templateUrl: 'tpls/views/sidebar.html',
            controller: 'MyCtrl',
            controllerAs : 'main'
        },
        'mainfeed@feeds': {
            templateUrl: 'tpls/views/mainfeed.html',
            controller: 'MyCtrl',
            controllerAs : 'main'
        }
    }
});

This is how the syntax look like for Nested views. 这就是嵌套视图的语法。 Please cross check with your Syntax. 请与您的语法交叉检查。
Note : This one is third party so we used ui.router.stateHelper 注意:这是第三方,因此我们使用了ui.router.stateHelper

angular.module('myApp', ['ui.router', 'ui.router.stateHelper'])
  .config(function(stateHelperProvider){
    stateHelperProvider.setNestedState({
      name: 'root',
      templateUrl: 'root.html',
      children: [
        {
          name: 'contacts',
          templateUrl: 'contacts.html',
          children: [
            {
              name: 'list',
              templateUrl: 'contacts.list.html'
            }
          ]
        },
        {
          name: 'products',
          templateUrl: 'products.html',
          children: [
            {
              name: 'list',
              templateUrl: 'products.list.html'
            }
          ]
        }
      ]
    });
  });

visit this more details.. https://github.com/angular-ui/ui-router/wiki/Nested-States-&-Nested-Views 请访问此更多详细信息。https://github.com/angular-ui/ui-router/wiki/Nested-States-&-Nested-Views

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM