问题
I'm not able to change the state from view page to edit page and vice versa in UI-Router. Things I've tried:
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"
}
}
})
In default.html
I'm loading only the view which I need to see when I first open the page.ie.,the edit page
<div ui-view="showViewA"></div>
which shows the edit page. On saving the edit page I need to replace the edit page with the view page which I have given a state showViewA@ViewshowViewA
. But it's not redirecting. Can I know where I went wrong?
回答1:
There is a working plunker
Let's pretend that this is the default.html
content:
<div >
<h2>The default view (layout)</h2>
<b>place holder for viewB</b>
<hr />
<div ui-view="viewB"></div>
</div>
Then to make our states working with these links:
<a ui-sref="showViewA">
<a ui-sref="showViewA.EditshowViewA">
<a ui-sref="showViewA.ViewshowViewA">
This would be the adjusted states definition (changes are new lines - old are left with commented values).
Parent state with inner view, injected into ui-view="viewB"
placeholder/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"
}
}
})
Children injecting its view into the same 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"
}
}
})
Check it here
来源:https://stackoverflow.com/questions/30443770/ui-router-routing-in-the-same-view-view-and-edit