【发布时间】:2017-03-16 19:25:15
【问题描述】:
https://plnkr.co/edit/VV13ty8XaQ20tdqibmFy?p=preview
预期
login 后dashboard 状态渲染dashboard.html,所有组件和ui-views 都应该渲染:tickers、tags、 社交(命名为 ui-view)和 feed。
结果
login 之后,dashboard 状态会呈现 dashboard.html,但是只有组件 tickers、tags 和 feed > 出现,但不是社交(命名的ui-view)
我觉得我的问题在于我从login 状态转换到dashboard 状态的某个地方。进入仪表板状态后,它会提供默认模板,即组件元素标签:<dash-module></dash-module>。这将呈现 dash.component 模板:dashboard.html 和控制器。但是,我无法访问仪表板状态对象中的社交视图。
dashboard.html
<div class="jumbotron text-center">
<h1>The Dashboard</h1>
</div>
<div class="row">
<tickers-module></tickers-module>
<tags-module></tags-module>
// Expecting the social-module-template.html to show below:
<div ui-view="social"></div>
<feed-module></feed-module>
</div>
带有仪表板组件的routerApp模块完整代码在Plnkr
// RouterApp module
////////////////////////////////////////////////////////////////////////////////
var routerApp = angular.module('routerApp', ['ui.router', 'tickers', 'tags', 'feed']);
routerApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
const login = {
name: 'login',
url: '/login',
templateUrl: 'login.html',
bindToController: true,
controllerAs: 'l',
controller: function($state) {
this.login = function() {
$state.go('dashboard', {});
}
}
}
const dashboard = {
name: 'dashboard',
url: '/dashboard',
params: {
ticker: {},
tags: {}
},
template: '<dash-module></dash-module>',
views: {
'' : {
templateUrl: 'dashboard.html',
},
'social' : {
templateUrl: 'social-module-template.html',
controller: function($state) {
console.log('Social init', $state.params);
}
}
}
}
$stateProvider
.state(login)
.state(dashboard);
})
tags.component('dashModule', {
templateUrl: 'dashboard.html',
controller: function($scope, $state) {
console.log('dashModule loaded!');
}
})
这是应该在<div ui-view="social"></div>中呈现社交html内容的部分
views: {
'' : {
templateUrl: 'dashboard.html',
},
'social' : {
templateUrl: 'social-module-template.html',
controller: function($state) {
console.log('Social init', $state.params);
}
}
}
【问题讨论】:
标签: javascript angularjs angular-ui-router state