我有一个关于Angular UI路由器的问题,当我在嵌套状态中使用多个命名视图。基本上我有一个抽象的状态与模板,指向两个命名的意见。这两个命名的视图在两个子状态中定义。我想保持URL固定到/测试。Angular Ui路由器多个命名视图和嵌套状态
当转换到任何一个子状态时,我只能看到对应于第一个子状态的视图。这是为什么?我真的希望有人能澄清这一概念对我来说,我可以学习
的jsfiddle是在这里:https://jsfiddle.net/adeopura/e2c5n14o/16/
angular.module('myApp', ['ui.state'])
.config(['$stateProvider', '$routeProvider',
function ($stateProvider, $routeProvider) {
$stateProvider
.state('test', {
abstract: true,
url: '/test',
views: {
'main': {
template: '<h1>Hello!!!</h1>' +
'<div ui-view="view1"></div>' +
'<div ui-view="view2"></div>'
}
}
})
.state('test.subs1', {
url: '',
views: {
'view1': {
template: "Im 1View1"
},
'view2': {
template: "Im 1View2"
}
}
})
.state('test.subs2', {
url: '',
views: {
'view1': {
template: "Im 2View1"
},
'view2': {
template: "Im 2View2"
}
}
});
}])
.run(['$rootScope', '$state', '$stateParams', function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
$state.transitionTo('test.subs1');//I see the data corresponding to the test.subs1
// Assume here that there are lots of different state transitions in between unrelated to the test1 state
$state.transitionTo('test.subs2');//I still see the data corresponding to the test.subs1, why is that?
}]);
你的“新”拨弄它缺少的外部引用 – beauXjames
更新了小提琴以供参考。 – AshD