我只想首先说,我尽可能多地查看了与此问题相关的堆栈溢出问题,但没有看到任何与我遇到的问题有关的问题。有些很相似,但又不完全一样。问题是这样的:
我设置了以下 $stateProvider:
$stateProvider.
state('root', {
url: '',
views: {
'ViewA': {
templateUrl: 'ViewA.html',
controller: ViewAController
},
'ViewB': {
templateUrl: 'ViewB.html',
controller: ViewBController
},
'ViewC': {
templateUrl: 'ViewC.html',
controller: ViewCContoller
}
}
});
以下是与之配套的index.Html:
<head>
<title>Angular PoC</title>
</head>
<body ng-controller="DashboardController">
<!-- Account View for logging in -->
<div ui-view="ViewA" ng-hide="currentlyLoggedIn"></div>
<!-- Used to toggle the two main views -->
<div ng-show="currentlyLoggedIn">
<button ng-click="activateViewB()"> View B </button>
<button ng-click="activateViewC()"> View C </button>
</div>
<!-- These are the two main views -->
<div ui-view="ViewB" ng-show="currentlyLoggedIn && currentViewB"></div>
<div ui-view="ViewC" ng-show="currentlyLoggedIn && currentViewC"></div>
</body>
这是ViewC.html:
<div>
This is ViewC
<div ui-view="ViewCDetails"></div>
</div>
我需要让所有 ViewA、B、C 基本上彼此独立运行,基本上它们都是自己的状态机。他们需要保持相同的视图,因为所有三个人都需要保持自己的状态,即使其他人之一发生变化。我遇到的最大问题是我无法初始化“ViewCDetails”,并且无法添加任何影响其中一个视图的状态而不托管其他两个视图。有没有一种方法可以添加仅影响其中一个视图而不会对其他两个视图产生不利影响的状态?另请注意,这应该是 SPA,因此它不是 URL 驱动的。
$stateProvider.
state('root', {
url: '',
views: {
'ViewA': {
templateUrl: 'ViewA.html',
controller: ViewAController
},
'ViewB': {
templateUrl: 'ViewB.html',
controller: ViewBController
},
'ViewC': {
templateUrl: 'ViewC.html',
controller: ViewCContoller
},
'ViewCDetails@root': {
templateUrl: 'ViewCDetails.html',
controller: ...
}
}
});
https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)