这是我的 $stateProvider 配置
app.config(function ($stateProvider, $urlRouterProvider) {
var helloState = {
name: 'uploadForm',
url: '/uploadForm',
templateUrl: 'templates/step_Form/form.html?v=' + new Date().getDay()
}
var uploadState = {
name: 'uploadForm.upload',
url: '/upload',
templateUrl: 'templates/step_Form/form-upload.html?v=' + new Date().getDay()
}
var contentState = {
name: 'uploadForm.content',
url: '/content',
templateUrl: 'templates/step_Form/form-content.html?v=' + new Date().getDay()
}
$stateProvider.state(helloState);
$stateProvider.state(uploadState);
$stateProvider.state(contentState);
})
是否可以测试状态是否已声明?
像这样:
if($stateProvider.state.??? == null)
$stateProvider.state(helloState);
因为我有另一个带有重定向的页面,并且它在配置中传递了两次并出现错误“State helloState is已经声明”
最佳答案
您可以使用 $state.get()
,它返回 $stateProvider
中所有已声明状态的数组。
当然,您必须在要执行检查的位置注入(inject) $state
。
关于javascript - 是否可以知道 ui.router 状态是否已在 AngularJS 中声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44065575/