gpt4 book ai didi

angularjs - Angular UI-Router,父 ui-view 呈现,但带有模板的 subview 不呈现

转载 作者:行者123 更新时间:2023-12-04 12:47:14 25 4
gpt4 key购买 nike

如果我有 index.html和:
<body>
<ui-view="home"></home>
</body>

然后在那个主 View 里面我渲染 frame.html里面有以下内容:
<div ui-view="home_content"></div>
在我的 app.js我一直在努力获得最内在的 ui-viewframe.html呈现另一个 html 模板。我能够呈现 home 中的内容 View 很好,但里面没有任何渲染 home_content .

我的 app.js ui-router 代码

    $stateProvider
.state('user', {
abstract: true,
template: '<ui-view/>',
data: {
access: AccessLevels.user
}
})

.state('user.home', {
url: '/home',
views: {
'home@': {
templateUrl: 'app/partials/home/frame.html',
controller: 'homeCtrl'
},
'home_content@home': {
templateUrl: 'app/partials/home/dashboard/index.html',
controller: 'dashboardCtrl'
}
}
});

似乎我可能在这一切都错了,不确定以上是否是正确的方法。

最佳答案

a working plunker
我希望你想在 child 中定位你 parent 的未命名 View ,所以 View 应该像这样定义:

$stateProvider
// here we define parent
.state('user', {
abstract: true,
// parent has UNNAMED view
template: '<ui-view/>', // this will be injected into index.html
... // ui-view=""
})
// child will partilly target parent
// and also itself
.state('user.home', {
url: '/home',
views: {
// here we target parent UNNAMED view
'': {
...
},
// here we target current state
// so we should use state name
'home_content@user.home': {
...
}
}
});
什么也可以代替 '' : { }我们可以使用 '@home' : {} (请参阅下面的文档)。
如果(如下面的评论中提到的)我们有 index.html,目标名为 home:
<div ui-view="home"></div>
我们可以使用 this plunker ,它重新定义了父抽象状态,如下所示:
$stateProvider
.state('user', {
abstract: true,
data: {
...
},
views : {
'home' : {
template: '<div ui-view=""></div>',
}
}
})
检查文档
View Names - Relative vs. Absolute Names

Behind the scenes, every view gets assigned an absolute name that follows a scheme of viewname@statename, where viewname is the name used in the view directive and state name is the state's absolute name, e.g. contact.item. You can also choose to write your view names in the absolute syntax.

For example, the previous example could also be written as:

.state('report',{
views: {
'filters@': { },
'tabledata@': { },
'graph@': { }
}
})

关于angularjs - Angular UI-Router,父 ui-view 呈现,但带有模板的 subview 不呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29544749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com