如果子控制器处于相同状态,则angular ui路由器-嵌套控制器-父控制器将启动两次
angular ui-router - nested controller - parent controller is initiated twice if child controller is in the same state
.state('home', {
url: '/home',
views: {
'main': {
templateUrl: './main.html',
controller: 'mainController'
},
'parent@home': {
templateUrl: './parent.html',
controller: 'parentController'
},
'child@home':{
templateUrl: './child.html',
controller: 'childController'
},
'otherPage@home': {
templateUrl: './other-page.html',
controller: 'otherController'
}
}
})
在parent.html中,我有子视图。基本上,父控制器(parentController(在此设置中启动两次。如果我删除child@home状态下,parentController只启动一次。我做错了什么,有更好的方法来定义这些状态吗?
index.html
<div class="maincontent" ui-view="main"></div>
main.html
<div class="maincontent container-fluid" ui-view="parent"></div>
<div class="maincontent container-fluid" ui-view="otherPage"></div>
parent.html
<div ui-view="child"></div>
像这样重新定义状态:
.state('home', {
url: '/home',
views: {
'': {
templateUrl: './main.html',
controller: 'mainController'
},
'parent@home': {
templateUrl: './parent.html',
controller: 'parentController'
},
'child@home':{
templateUrl: './child.html',
controller: 'childController'
},
'otherPage@home': {
templateUrl: './other-page.html',
controller: 'otherController'
}
}
})
根据我的理解,带有空键的视图将作为主状态的默认视图加载。
通过这种方式,您的main.html
模板将包含指向其他ui-views
的指针,就像您对parent
和otherPage
所做的那样。
我没能测试这个,因为我不在我的开发PC上,但我认为它应该能工作,因为它是我的几个AngularJS项目中遵循的格式。
相关文章:
- 在指令控制器中使用$attrs时出现问题
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 我的jQuery插件参数没有正确启动,遇到了问题
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 从控制器返回后Ajax启动事件激发
- 为什么我的控制器没有启动函数.js脚本
- angularjs控制器未启动
- Angular JS$location.path(..)未启动路由控制器
- AngularJS:如何重新启动控制器以更新要监视的数据源模型
- 使用 JavaScript 从控制器启动 Excel 文件
- “控制器”的AngularJS代码无法启动
- 控制器中的$watch在将项推入指令中的数组时未启动
- Ionic:应用程序启动时角度控制器未运行
- 如何从1个控制器启动倒计时计时器并显示在其他angularjs中
- 如何在Ember JS控制器加载时启动一个函数?
- Ionic谷歌地图控制器没有重新启动
- 如果子控制器处于相同状态,则angular ui路由器-嵌套控制器-父控制器将启动两次
- Sencha Touch 2控制器初始化/启动不'不要开火
- 如何在 CFWheels, for Ajax 中启动控制器/操作
- 在控制器将数据发送到jsp之后,如何启动脚本