UI Router 中的双重嵌套视图 [英] Doubly-nested views in UI Router

查看:15
本文介绍了UI Router 中的双重嵌套视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 angular-ui,特别是使用 ui-router 模块来做一些嵌套的视图.我在部分渲染中遇到了问题:

Playing around with angular-ui and specifically using the ui-router module to do some nested views. I'm having trouble getting a partial to render within a partial:

嵌套如下:

index.html
    -main.form.html
    -main.sidebar.html
        -sidebar.slider.html

我当前的 app.js 设置是:

$stateProvider
        .state('main', {
            url: '/',
            views: {
                'sidebar': {
                    templateUrl: 'views/partials/main.sidebar.html',
                    views: {
                        'slider': {
                            templateUrl: 'views/partials/sidebar.slider.html'
                        }

                    }

                },
                'form': {
                    templateUrl: 'views/partials/main.form.html',

                },
                'tribute': {
                    templateUrl: 'views/partials/main.tribute.html',
                },
                'submit': {
                    templateUrl: 'views/partials/submit.html',
                }
            }
        })

所有其他部分加载,我可以在浏览器中看到 ui-view 指令加载,但实际部分没有呈现(div 只包含 ui-view="sidebar.slider" 文字)

All other partials load and I can see the ui-view directive loading in the browser, but the actual partial isn't rendered (the div just contains the ui-view="sidebar.slider" literal)

有什么想法吗?

推荐答案

在一个状态内的视图嵌套是通过他们的 相对/绝对 视图名称​​(不是通过对象嵌套)

The view nesting, inside of one state, is done via their relative/absolute view name (not via object nesting)

假设 templateUrl 包含 ui-view="slider",那么我们必须绝对定位该 view 名称

Let's say, that the templateUrl contains the ui-view="slider", then we have to target that view name absolutely

$stateProvider
   .state('main', {
     url: '/',
     views: {
      'sidebar': {
         templateUrl: 'views/partials/main.sidebar.html',
       },
      // this view definition is on the same level
      // but the absolute name says, that it should be searched
      // inside of the 'main' state
      'slider@main': {
         templateUrl: 'views/partials/sidebar.slider.html'
      },
      ...

这里的关键是视图'slider@main'的名称,它包含来自视图名称'slider'的分隔符'@'和状态名称'main'.检查这些以了解更多详情:

the key here is the name of the view 'slider@main', which contains from view name 'slider' delimiter '@' and the state name 'main'. Check these for more details:

这篇关于UI Router 中的双重嵌套视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆