问题描述
我有一个html页面父亲,
I have an html page father with:
<div id="..." class="container">
<pp-nav></pp-nav>
<div ui-view></div>
</div>
这是我的控制人,有一个父亲和两个孩子:
This is my controller with a father and two child:
export function routerConfig($stateProvider: angular.ui.IStateProvider, $urlRouterProvider: angular.ui.IUrlRouterProvider) {
$stateProvider
.state('gestionePeP', {
url: '/gestionePeP',
templateUrl: '.../gestionePeP/gestionePeP.html'
})
.state('gestionePeP.puntiAttivazione', {
url: '/puntiAttivazione',
templateUrl: '.../gestionePeP/puntiAttivazione.html'
})
.state('gestionePeP.gestioneContenuti', {
url: '/gestioneContenuti',
templateUrl: '.../gestionePeP/gestioneContenuti.html'
});
我希望当我转到父页面时,stateprovider打开带有第一个孩子的父html页面.我该怎么办?
I want that when I go to the father page the stateprovider opens the father html page with the first child inside it.How can I do it?
如果我使用
ui-sref="gestionePeP.puntiAttivazione"
它会打开正确的页面.但是我想要没有任何点击的相同行为.我尝试了$ state.go('gestionePeP.puntiAttivazione'),但是它循环了.我该怎么解决?
it opens the right page. But I want the same behaviour without any click.I tried $state.go('gestionePeP.puntiAttivazione') but it goes in loop.How can I solve?
推荐答案
到目前为止,我发现的最好方法是:
Still far the best way I found is here:
只需将这些行添加到某些.run()
just add these lines to some .run()
app.run(['$rootScope', '$state', function($rootScope, $state) {
$rootScope.$on('$stateChangeStart', function(evt, to, params) {
if (to.redirectTo) {
evt.preventDefault();
$state.go(to.redirectTo, params)
}
});
}]);
并使用默认 redirectTo
扩展状态def:
And extend state def with default redirectTo
:
.state('gestionePeP', {
url: '/gestionePeP',
templateUrl: '.../gestionePeP/gestionePeP.html',
// this will set redirect target
redirectTo: 'gestionePeP.puntiAttivazione',
})
检查该链接与工作中的矮人
EXTEND-如何使ng.ui.IState知道新属性redirectTo
?
EXTEND - how to make ng.ui.IState aware of the new property redirectTo
?
只需将以下行添加到您的代码中即可:
Just add these lines to your code:
declare module angular.ui { export interface IState { redirectTo?: string; } }
这篇关于$ stateprovider中带有打字稿的父亲中的默认孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!