我无法在 UI-Router 中将状态从查看页面更改为编辑页面,反之亦然。 我尝试过的事情:
Controller :
$stateProvider
.state('showViewA', {
views: {
" ": {
template: "default.html",
controller:"DefaultController.ts"
},
"viewB@showViewA": {
template: "viewPage.html",
controller:"DefaultController.ts"
}
}
})
.state('showViewA@EditshowViewA', {
views: {
" ": {
template: "defaultEdit.html",
controller:"DefaultEditController.ts"
}
}
})
.state('showViewA@ViewshowViewA', {
views: {
" ": {
template: "defaultShow.html",
controller:"DefaultShowController.ts"
}
}
})
在default.html
中,我仅加载第一次打开页面时需要看到的 View ,即编辑页面
<div ui-view="showViewA"></div>
显示编辑页面。保存编辑页面时,我需要将编辑页面替换为我已指定状态 showViewA@ViewshowViewA
的 View 页面。但它不是重定向。我能知道我哪里错了吗?
最佳答案
假设这是 default.html
内容:
<div >
<h2>The default view (layout)</h2>
<b>place holder for viewB</b>
<hr />
<div ui-view="viewB"></div>
</div>
然后让我们的状态使用这些链接:
<a ui-sref="showViewA">
<a ui-sref="showViewA.EditshowViewA">
<a ui-sref="showViewA.ViewshowViewA">
这将是调整后的状态定义(更改为新行 - 旧行保留注释值)。
具有内部 View 的父状态,注入(inject)ui-view="viewB"
占位符/ anchor
.state('showViewA', {
url: '/',
views: {
//" ": {
"": {
//template: "default.html",
templateUrl: "default.html",
//controller:"DefaultController.ts"
controller: "DefaultController"
},
"viewB@showViewA": {
//template: "viewPage.html",
templateUrl: "viewPage.html",
//controller: "DefaultController.ts"
controller: "DefaultController"
}
}
})
子级将其 View 注入(inject)同一个 ui-view="viewB"
//.state('showViewA@EditshowViewA', {
.state('showViewA.EditshowViewA', {
views: {
//" ": {
"viewB": {
//template: "defaultEdit.html",
templateUrl: "defaultEdit.html",
//controller:"DefaultEditController.ts"
controller: "DefaultEditController"
}
}
})
//.state('showViewA@ViewshowViewA', {
.state('showViewA.ViewshowViewA', {
views: {
//" ": {
"viewB": {
//template: "defaultShow.html",
templateUrl: "defaultShow.html",
//controller:"DefaultShowController.ts"
controller: "DefaultShowController"
}
}
})
检查一下here
关于javascript - 同一 View 中的 UI-Router 路由(查看和编辑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30443770/