ui-router
状态转换有两个问题:
我正在使用的代码:
$stateProvider
.state("root.test", {
abstract: true,
url : "/abc",
template: '<ui-view/>'
})
.state("root.test.edit", {
url : "/:testId",
views: {
"@": {
template : require('../edit.html'),
controller: "TestEditController"
}
},
params: {
testObject: {value: null}
},
redirectTo: 'root.test.edit.select',
resolve: {
testObject: function () {
console.log('test object resolved');
}
}
})
.state("root.test.edit.select", {
url : "/select",
views: {
"main@root.test.edit": {
template : require('../select.html'),
controller: "TestEditSelectController"
}
},
resolve: {
selectObject: function () {
console.log('select object resolved');
},
}
})
.state("root.test.edit.select.dialogBox", {
params: {
testObject: {value:null}
},
resolve: {
testObject: function () {
console.log('dialog box opens');
},
},
onEnter: ['$state', '$uibModal',
function ($state, $uibModal) {
$uibModal.open({
template : require('../dialogBox.html'),
controller: 'DialogBoxController',
resolve : {
testObject: function () {
return testObject;
}
}
}).result.then(function (testObject) {
$state.go('root.test.edit.select', { testObject: testObject}, {reload: true});
}, function () {
$state.go('root.test.edit.select');
}
);
}]
})
对于上面提到的第一个问题:
如果我处于root.test.edit.select
状态,当我点击按钮打开状态为root.test.edit.select.dialogBox
的对话框时,test object resolved
- &gt; select object resolved
- &gt; dialog box opens
所有内容都打印在控制台上,这意味着所有父母都会得到解决。但是当我关闭对话框并再次打开它时,只打印dialog box opens
,这就是第一次打开对话框时的情况。
对于上面提到的第二个问题:
如果我处于root.test.edit.select
状态,并使用浏览器按钮刷新页面,test object resolved
- &gt; select object resolved
- &gt; test object resolved
- &gt;打印select object resolved
,即父母和孩子都被解析两次。
我检查了我提到的here时的错误,但根据该帖子,一切都很好。