默认 child inside father in $stateprovider with typescript
default child inside father in $stateprovider with typescript
我有一个 html 页面父亲:
<div id="..." class="container">
<pp-nav></pp-nav>
<div ui-view></div>
</div>
这是我的控制器,有一个父亲和两个 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 页面,其中包含第一个 child。
我该怎么做?
如果我把 link 放在父亲的按钮里面
ui-sref="gestionePeP.puntiAttivazione"
打开正确的页面。但是我想要没有任何点击的相同行为。
我试过 $state.go('gestionePeP.puntiAttivazione') 但它进入循环。
我该如何解决?
我找到的最好的方法仍然是这里:
只需将这些行添加到一些 .运行()
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
:
扩展状态定义
.state('gestionePeP', {
url: '/gestionePeP',
templateUrl: '.../gestionePeP/gestionePeP.html',
// this will set redirect target
redirectTo: 'gestionePeP.puntiAttivazione',
})
检查 以确保工作正常
EXTEND - 如何让 ng.ui.IState 了解新的 属性 redirectTo
?
只需将这些行添加到您的代码中:
declare module angular.ui { export interface IState { redirectTo?: string; } }
我有一个 html 页面父亲:
<div id="..." class="container">
<pp-nav></pp-nav>
<div ui-view></div>
</div>
这是我的控制器,有一个父亲和两个 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 页面,其中包含第一个 child。 我该怎么做?
如果我把 link 放在父亲的按钮里面
ui-sref="gestionePeP.puntiAttivazione"
打开正确的页面。但是我想要没有任何点击的相同行为。 我试过 $state.go('gestionePeP.puntiAttivazione') 但它进入循环。 我该如何解决?
我找到的最好的方法仍然是这里:
只需将这些行添加到一些 .运行()
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
:
.state('gestionePeP', {
url: '/gestionePeP',
templateUrl: '.../gestionePeP/gestionePeP.html',
// this will set redirect target
redirectTo: 'gestionePeP.puntiAttivazione',
})
检查
EXTEND - 如何让 ng.ui.IState 了解新的 属性 redirectTo
?
只需将这些行添加到您的代码中:
declare module angular.ui { export interface IState { redirectTo?: string; } }