gpt4 book ai didi

javascript - ui-router 多个命名嵌套 View

转载 作者:行者123 更新时间:2023-11-30 16:55:07 25 4
gpt4 key购买 nike

我有一个像这样的嵌套 View

<div ui-view="master" id="ng-view">
<div class="container-fluid height-full">
<div ui-view="globalNavigationPanel" class="row"></div>
<div ui-view="detail" id="detailContent" class="row"></div>
</div>
</div>

这是我的解析器

function resolveShell()
{
return {
'views': {
'master': {
templateUrl: 'core/views/shell.html',
controller: 'core/controllers/shellcontroller.js',
controllerAs: 'vm',
},
'globalNavigationPanel': {
templateUrl: 'core/views/globalNavigationPanel',
controller: 'core/controllers/globalNavigationPanelController.js',
controllerAs: 'gpvm',
}
},
'resolve': {
load: [
'$q', '$rootScope', ($q, $rootScope) => {
var dependencies = [
'core/controllers/shellcontroller.js',
'core/controllers/globalNavigationPanelController.js'
];
return resolveDependencies($q, $rootScope, dependencies);
}
]
}
};
}

当我设置状态时,我可以看到所有文件已下载并且 shellcontroller.js 被调用,但不是 globalNavigationPanelController

我也看不到 globalNavigationPanel View 更新。

我基本上可以设置状态并解析多个命名嵌套 View 吗?

最佳答案

这是因为我们使用了多个 View ,它们嵌套在一个状态中。这意味着,我们必须使用绝对命名。

这样,我们可以指示 UI-Router,第二个 View 应该被放置到当前状态的其他 View 中。您所在州的名称并不明显,但让我们想象一下它是“shell”

'views': {
'master': {
...
},
'globalNavigationPanel@shell': {
....
}
},

现在,我们的 'shell' 状态的模板应该是 (我的意思是 templateUrl: 'core/views/shell .html',)

<div class="container-fluid height-full">
<div ui-view="globalNavigationPanel" class="row"></div>
<div ui-view="detail" id="detailContent" class="row"></div>
</div>

index.html 应该只包含:

<div ui-view="master" id="ng-view">
</div>

因为母版将包含“globalNavigationPanel”的占位符

同时查看文档

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@': { }
}
})

Notice that the view names are now specified as absolute names, as opposed to the relative name. It is targeting the 'filters', 'tabledata', and 'graph' views located in the root unnamed template. Since it's unnamed, there is nothing following the '@'. The root unnamed template is your index.html.

EXTEND - 有 is a working example

这是状态定义:

  .state('shell', {
url: '/shell',
views: {
'master' : {
templateUrl: 'core/views/shell.html',
controller: 'shellcontroller',
controllerAs: 'vm',
},
'globalNavigationPanel@shell': {
templateUrl: 'core/views/globalNavigationPanel.html',
controller: 'globalNavigationPanelController',
controllerAs: 'gpvm',
}
}
})

这些是观点

templateUrl: 'core/views/shell.html',

<h2>shell</h2>

<p>{{text}}</p>

<hr />

<div class="container-fluid height-full">
<div ui-view="globalNavigationPanel" class="row"></div>
<div ui-view="detail" id="detailContent" class="row"></div>
</div>

templateUrl: 'core/views/globalNavigationPanel.html',

<h3>globalNavigationPanel</h3>

<p>{{text}}</p>

而索引仅包含:

<div ui-view="master" id="ng-view"></div>

实际检查 here

关于javascript - ui-router 多个命名嵌套 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29835038/

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