https://plnkr.co/edit/XnDUIqfVuBS2Hr2N1ooy?p=preview
我有一个名为container
的顶级州,其中包含指定的观看次数dashboard
和feed
。
在dashboard
视图模板的内部,我有<div ui-view="tickers"></div>
,我想加载tickers
州,我该怎么做?
这是通过在命名视图dashboard@container
中添加内容来完成的吗?
// Container module
////////////////////////////////////////////////////////////////////////////////
var container = angular.module('container', [ 'ui.router' ])
container.config(function($stateProvider) {
const container = {
name: 'container',
url: '/container',
views: {
'': {
templateUrl: 'container-template.html',
controller: function($scope) {
console.log('CONTAINER view $state');
}
},
'dashboard@container': {
templateUrl: 'dashboard-template.html',
controller: function($scope) {
console.log('DASHBOARD view $state');
}
},
'feed@container': {
templateUrl: 'feed-template.html',
controller: function($scope) {
console.log('FEED view $state');
}
}
}
}
$stateProvider.state(container);
});
<div>
<div class="fl w100">
<em>Container state</em>
</div>
<div ui-view="dashboard" class="fl"></div>
<div ui-view="feed" class="fl"></div>
</div>
<div class="dashboard-state">
<em>Dashbaord state</em>
<div ui-view="tickers"></div>
</div>
// Tickers module
var tickers = angular.module('tickers', ['ui.router'])
tickers.config(function($stateProvider) {
const tickers = {
parent: 'dashboard',
name: 'tickers',
url: '/tickers',
params: {
ticker: {}
},
views: {
'': {
templateUrl: 'tickers-template.html',
controller: function($scope, $state) {
console.log('TICKERS view $state');
$scope.tickers = [
{ id: 1, ticker: 'AAPL' },
{ id: 2, ticker: 'GOOG' },
{ id: 3, ticker: 'TWTR' }
];
$scope.clickTicker = function(ticker) {
console.log('ticker', ticker)
$state.go('tags', { ticker: ticker });
}
}
},
'tags@tickers': {
templateUrl: 'tags-template.html',
controller: function($scope) {
console.log('TAGS view $state');
}
}
}
}
$stateProvider.state(tickers);
})
// TickersApp module
////////////////////////////////////////////////////////////////////////////////
var tickersApp = angular.module('tickersApp', ['ui.router', 'container', 'tickers']);
tickersApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
const login = {
name: 'login',
url: '/login',
templateUrl: 'login-template.html',
bindToController: true,
controllerAs: 'l',
controller: function($state) {
this.login = function() {
$state.go('container', { });
}
}
}
$stateProvider
.state(login);
});
答案 0 :(得分:1)
仍然在等待更多答案,但到目前为止,我使用tickers.component
dashboard-template.html
工作了
https://plnkr.co/edit/6dLIk1vq6M1Dsgy8Y4Zk?p=preview
<div class="dashboard-state">
<div class="fl w100">
<em>Dashbaord state</em>
</div>
<!--<div ui-view="tickers"></div>-->
<tickers-module></tickers-module>
</div>
tickers.component('tickersModule', {
templateUrl: 'tickers-template.html',
controller: function($scope, $state) {
console.log('TICKERS component');
$scope.tickers = [
{ id: 1, ticker: 'AAPL' },
{ id: 2, ticker: 'GOOG' },
{ id: 3, ticker: 'TWTR' }
];
$scope.clickTicker = function(ticker) {
console.log(' Ticker clicked!', $state)
$state.go('tags', { ticker: ticker });
}
}
});
答案 1 :(得分:0)
我认为你应该在容器上使用不同的状态:
$ stateProvider .state(&#39; container&#39;,{ url:&#39; / container&#39;, templateUrl:&#39;&#39; })
.state('container.feed', {
url: '/container/feed',
templateUrl: 'partial-home.html'
})
.state('container.dashboard', {
url: '/container,
templateUrl: 'partial-home.html'
})
并使用ui-sref