【发布时间】:2016-01-20 11:19:41
【问题描述】:
在我的 js 应用程序中,我通过 angular ui-router 在配置 $stateProvider 部分中有这个:
.state('login', {
url: '/login',
templateUrl: 'app/login/login.tmpl.html',
controller: 'LoginCtrl as login'
})
.state('app', {
abstract: true,
url: '/',
views: {
'main': { templateUrl: 'app/main/main.html' }
}
})
.state('app.reports', {
url: 'reports',
views: {
'': {templateUrl: 'app/templates/reports.tmpl.html'},
'devices@app.reports': {
templateUrl: 'app/templates/devices.tmpl.html',
controller: 'DevicesCtrl as devicesCtrl'
},
'graphics@app.reports': {...}
}
})
在 index.html 我有:
<body ng-controller="MainCtrl as main" >
<section ui-view>
<div ui-view="main"></div>
</section>
....
</body>
仅当我在 ui-view 中嵌套了 ui-view="main" 时才有效。
使用 ui-router 是否正确?
在main.html 中,我有一些页面的页眉、页脚和一些通用信息。
但我有另一个状态,“登录”,在其中我将拥有自己的模板。但在index.html 中,他们将加载ui-view,而不是ui-view="main"。
如何重构 index.html 和 js 以避免在 index.html 中嵌套 ui-view?
还是我有正确的方法?
【问题讨论】:
标签: javascript angularjs angular-ui-router