【发布时间】:2014-05-18 07:59:02
【问题描述】:
我正在尝试 ui-router 插件的嵌套视图功能,但遇到了我不知道如何解决的问题。 显示问题的代码可以在http://jsfiddle.net/3c9h7/1/ 找到:
var app = angular.module('myApp', ['ui.router']);
app.config(function($stateProvider) {
return $stateProvider.state('root', {
template: "<div class='top' ui-view='viewA'></div><div class='middle' ui-view='viewB'></div>"
}).state('root.step1', {
url: '',
views: {
'viewA': {
template: '<h1>View A</h1>'
}
}
}).state('root.step1.step2', {
url: '/step2',
views: {
'viewB': {
template: '<h1>View B</h1>'
}
}
});
});
app.controller('MainCtrl', [
'$scope', '$state', function($scope, $state) {
$state.transitionTo('root.step1.step2');
}
]);
<div ng-app='myApp' ui-view ng-controller='MainCtrl'>
</div>
因此,代码通过使用 $state.go 方法激活“root.step1.step2”状态(https://github.com/angular-ui/ui-router/wiki/Quick-Reference#stategoto--toparams--options) 根据 ui-router 文档:
当应用程序处于特定状态时 - 当状态处于 “活跃”——它的所有祖先状态也是隐式活跃的。
因此,我希望“root.step1”和“root”将处于活动状态并且按预期工作,但“viewB”没有填充模板,正如您在 jsfiddle 示例中看到的那样:顶部 viewA(root. step1) 可以,但是中间的viewB(root.step1.step2) 是空的。 我做错了什么?
【问题讨论】:
标签: angularjs angular-ui-router