简体   繁体   English

角度UI路由器-组件-父级-子级-嵌套-视图未加载

[英]Angular UI-Router - Component - Parent - Child - Nested - View not load

I've question about ui-router and components. 我对ui路由器和组件有疑问。 I've switched from non-component based structure to component based structure. 我已经从基于非组件的结构切换到基于组件的结构。 I love it, it´s very clear and very easy to manage/handle the resources, excepts the damn routing process. 我喜欢它,除了该死的路由过程外,它非常清楚而且易于管理/处理资源。 my app is very very complex and has many layers of modules and components like this: 我的应用程序非常复杂,并且具有许多类似的模块和组件层:

app 应用

- Layout
- LogicCode

module

- Layout
- LogicCode
- Config/Routing

Components
    ComponentA
        - Layout
        - LogicCode
        - Config/Routing

    ComponentB
        - Layout
        - LogicCode
        - Config/Routing

in app.Layout is an 在app.Layout是一个

<div ui-view="module" />

element 元件

in module.Layout an 在module.Layout一个

<div ui-view="moduleContent" />

element 元件

the module.Config takes the routing for the hole module eg: 该模块。配置为孔模块进行路由,例如:

$stateProvider
.state({
    // abstract: true,
    name: 'my_module',
    url: '/my_module',
    views: {
        'module': { component: 'my_module' }
    }
});

the component.Config takes the routing for each component eg: component.Config接受每个组件的路由,例如:

$stateProvider
// This is a list view e.g. for orders or something like that
.state({
    name: 'my_module.componentA',
    url: '/componentA',
    resolve: {
        //...
    },
    views: {
        'moduleContent': { component: 'componentAList' }
    }
})
// this should be the detail view (abstract cause it has many sub components)
.state({
    name: 'my_module.componentA.item',
    url: '/:itemId',
    views: {
        'moduleContent': { component: 'componentAItem' }
    },
    resolve: {
        // ...
    },
    abstract: true,
    redirectTo: 'my_module.componentA.item.general'
})
// this is the major item view
.state({
    name: 'my_module.componentA.item.general',
    url: '/',
    component: 'componentAItemGeneral'
})
// this is any other item view
.state({
    name: 'my_module.componentA.item.positions',
    url: '/',
    resolve: {
        // ...
    },
    component: 'componentAItemPositions'
});

if I link state "my_module" everything works fine, also when link state "my_module.componentA" all fine. 如果我链接状态“ my_module”一切正常,那么当链接状态“ my_module.componentA”一切正常时。 but if I try to link "my_module.componentA.item" the view will not change, the controller of the component works fine but the view doesn't change. 但是,如果我尝试链接“ my_module.componentA.item”,则视图不会更改,该组件的控制器工作正常,但视图不会更改。 the same when I link "my_module.componentA.item.general" or "my_module.componentA.item.positions". 链接“ my_module.componentA.item.general”或“ my_module.componentA.item.positions”时,情况相同。 Where is the problem? 问题出在哪儿? May you can open my eyes - thanks a lot! 愿你睁开我的眼睛-非常感谢!

Hopefully you've already solved this by now, but just in case someone stumbles on this and wants to know what happened here... 希望您现在已经解决了这个问题,但是以防万一有人偶然发现这个问题并想知道这里发生了什么...

The way you have it set up, your state 'my_module.componentA.item' is trying to look for a <div ui-view="moduleContent"></div> inside of the html of componentAList , because you're currently pointing it to a named view inside its parent. 设置方式,状态'my_module.componentA.item'试图在componentAList的html内查找<div ui-view="moduleContent"></div> ,因为您当前正在指向它到其父级内部的命名视图。 If you wanted it to do that, you may just need to add that view to that component's template. 如果您希望这样做,则可能只需要将该视图添加到该组件的模板中即可。

However, it looks to me like you intended for it to look for the <div ui-view="moduleContent"></div> inside the html of my_module . 但是,在我看来,您想要在my_module的html内查找<div ui-view="moduleContent"></div> To do that, change the views property in your state declaration for state 'my_module.componentA.item' to 为此,将状态声明'my_module.componentA.item'状态声明中的views属性更改为

views: {
    'moduleContent@^.^': { component: 'componentAItem' }
},

or 要么

views: {
    'moduleContent@my_module': { component: 'componentAItem' }
},

This will tell it to look for a view of that name in the html of the grandparent rather than the parent. 这将告诉它在祖父母(而不是父母)的html中查找该名称的视图。

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

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