[英]how to use multiple views in nested states in Angular ui-router?
I am working on an Angular app which has multiple nested states. 我正在开发一个具有多个嵌套状态的Angular应用程序。
The initial ui-view either loads the app or the login page based on the authentication. 初始ui视图基于身份验证加载应用程序或登录页面。 Once the app is loaded, it contains the top header and another named ui-view 'content' which would load the content based on the current tab/navigation.
加载应用程序后,它包含顶部标题和另一个名为ui-view“ content”的内容,它们将根据当前选项卡/导航加载内容。
$stateProvider.state( 'app.home.dashboard', {
url: 'home/dashboard',
views: {
"content@app.home": {
controller: 'DashboardCtrl',
templateUrl: 'app/home/dashboard.html'
}
},
data: {
authenticate: true
},
resolve: {
}
}) })
This is the dashboard state configuration. 这是仪表板状态配置。
Problem : Now I want to load multiple data widgets in the dashboard, each of them would have their own resolves, templates and views. 问题:现在,我想在仪表板上加载多个数据小部件,每个小部件将具有自己的解析,模板和视图。
So once the dashboard is loaded all those multiple child views should start loading automatically. 因此,一旦加载了仪表板,所有这些多个子视图都应自动开始加载。
.state( 'app.home.dashboard.dataWidget.spend', {
url: '',
views: {
"spend@app.home.dashboard": {
controller: 'DashboardDataWidgetCtrl',
templateUrl: 'app/home/dashboard/data-widget.html'
}
},
data: {
authenticate: true
},
resolve: {
spend: ['userInfo','apiDataFactory', function(userInfo, apiDataFactory) {
apiDataFactory.getSpend()
.then(function(response) {
return response.data;
});
}]
}
}) })
.state( 'app.home.dashboard.dataWidget.touchPoint', {
url: '',
views: {
"touchPoint@app.home.dashboard": {
controller: 'DashboardDataWidgetCtrl',
templateUrl: 'app/home/dashboard/data-widget.html'
}
},
data: {
authenticate: true
},
resolve: {
spend: ['userInfo','apiDataFactory', function(userInfo, apiDataFactory) {
apiDataFactory.getTouchPoint()
.then(function(response) {
return response.data;
});
}]
}
}) })
But when I go to dashboard state these child states do not load automatically. 但是,当我进入仪表板状态时,这些子状态不会自动加载。 How can I achieve this?
我该如何实现? What am I doing wrong?
我究竟做错了什么?
Created a small plunker app to illustrate my problem and approach. 创建了一个小型插件应用程序来说明我的问题和方法。 How should I resolve data into the widgets simultaneously?
我应该如何同时将数据解析到小部件中?
I have updated your plunk with the fixes. 我已经用修复程序更新了您的小精灵。 The dashboard state was the problem:
仪表板状态是问题所在:
.state('app.home.dashboard', {
url: 'home/dashboard',
views: {
"content@app.home": {
controller: 'appDashboardCtrl',
templateUrl: 'dashboard.html'
},
"visit@app.home.dashboard": {
controller: 'appContactCtrl',
templateUrl: 'contact.html'
},
"reach@app.home.dashboard": {
controller: 'appAboutCtrl',
templateUrl: 'about.html'
}
}
})
Please see: http://plnkr.co/edit/fDLQTIpdfROageEtBPZv?p=preview 请参阅: http : //plnkr.co/edit/fDLQTIpdfROageEtBPZv?p=preview
You may want to reference the information here: 您可能要在这里参考信息:
https://github.com/angular-ui/ui-router/wiki/multiple-named-views https://github.com/angular-ui/ui-router/wiki/multiple-named-views
Once you publish your templates I may be able to help further. 一旦您发布了模板,我也许就能提供进一步的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.