[英]Angular.js - ui-router not injecting view
I have a problem with ui-router for angular.js. 我对于angular.js的ui-router有问题。 I am currently working on a project with angular.js and using ui-router as router.
我目前正在开发一个带有angular.js的项目,并使用ui-router作为路由器。 The problem now is, that I want to have a nested view as like this:
现在的问题是,我希望有一个嵌套视图,如下所示:
views/settings/index.html (also an previously created template in ui-router) views / settings / index.html (也是ui-router中以前创建的模板)
<div class="settings">
[...]
<div class="settings-content" ui-view="content"></div>
</div>
app.js app.js
$stateProvider.state('settings', {
url: '/settings',
views: {
main: {
templateUrl: 'views/settings/index.html',
controller: 'SettingsController'
},
"content": {
templateUrl: 'views/settings/privacy.html',
controller: 'SettingsController'
}
},
ncyBreadcrumb: { label: 'Settings' }
})
Now the problem I have is, that the defined content
template is not injected into the ui-view="content"
div. 现在我遇到的问题是,定义的
content
模板没有注入到ui-view="content"
div中。 The main content ( views/settings/index.html
) is loading properly. 主要内容(
views/settings/index.html
)正确加载。 And in nested states it's also possible to add a template into the ui-view="content"
with the same "string": Object
. 在嵌套状态下,还可以使用相同的
"string": Object
将模板添加到ui-view="content"
。
How does this come? 这是怎么来的? Thanks in advance!
提前致谢!
You must use the viewName@stateName
syntax as stated here . 您必须使用此处所述的
viewName@stateName
语法。
Try this 尝试这个
$stateProvider.state('settings', {
url: '/settings',
views: {
main: {
templateUrl: 'views/settings/index.html',
controller: 'SettingsController'
},
"content@settings": {
templateUrl: 'views/settings/privacy.html',
controller: 'SettingsController'
}
},
ncyBreadcrumb: { label: 'Settings' }
})
I have used the ui-router module in my demo application. 我在我的演示应用程序中使用了ui-router模块。
You need to specify the hierarchy in your view. 您需要在视图中指定层次结构。
The parent view is not specified to child view so you must use ViewName@parentState 父视图未指定给子视图,因此您必须使用ViewName @ parentState
https://github.com/singhmohancs/angularDemo/tree/master/app/modules https://github.com/singhmohancs/angularDemo/tree/master/app/modules
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.