UI-Router 的绝对命名与您使用的方式有点不同
.state('projectsWs.tasks.detail', {
url: "/:taskId",
views: {
"mainView@": {
templateUrl: "/app/projects/templates/index.php"
},
// this won't work, because the part after @
// must be state name
"innerView@mainView": {
// so we would need this to target root, index.html
"innerView@": {
// or this to target nested view inside of a parent
"innerView": {
// which is the same as this
"[email protected]": {
检查:
视图名称 - 相对名称与绝对名称
小引用:
在幕后,每个视图都会被分配一个绝对名称,该名称遵循以下方案:viewname@statename
,其中 viewname 是视图指令中使用的名称,状态名称是状态的绝对名称,例如联系人.项目。您还可以选择以绝对语法编写视图名称。
我创建了一个工作示例在这里,各州都是这样的
$stateProvider
.state('projectsWs', {
template: '<div ui-view="mainView" ></div>' +
'<div ui-view="innerView" ></div>',
})
$stateProvider
.state('projectsWs.tasks', {
url: "/tasks",
views: {
"mainView": {
//templateUrl: "/app/projects/templates/index.php"
template: "<div>main view tasks </div>",
},
"innerView": {
//templateUrl: "/app/projects/templates/tasks.php",
template: "<div>inner view tasks </div>",
}
}
})
.state('projectsWs.tasks.detail', {
url: "/:taskId",
views: {
"mainView@projectsWs": {
//templateUrl: "/app/projects/templates/index.php"
template: "<div>main view task {{$stateParams | json }} </div>",
},
"innerView@projectsWs": {
//templateUrl: "/app/projects/templates/tasks.php",
template: "<div>inner view task {{$stateParams | json }} </div>",
}
}
});
我们可以看到,祖父母projectsWs
正在注入index.html(root)<div ui-view="">
一些模板,有两个命名锚点:
template: '<div ui-view="mainView" ></div>' +
'<div ui-view="innerView" ></div>',
然后在列表和详细状态中使用,并使用相对名称和绝对名称
核实here在行动