我的申请因标题错误而失败。当我为我的 ui-router 定义太多状态时,会发生此错误。以前当我发布这个问题时,我被告知这与帖子中讨论的错误相同,“运行 concat/uglify 后 Angular “状态已定义”错误”。我按照帖子的指示更改了我的代码,将其包装在一个闭包中。更改后,代码继续以相同的方式运行。也就是说,在所有定义的状态下,代码都因错误而失败。当我减少状态数时,代码运行良好。我已经包含了下面的代码,但我只显示了一种为最小化代码而定义的状态。我当前的代码有 40 个状态,当应用程序完成时,我的状态数将增加一倍以上。每个状态有 6 个视图。注释代码是我最初使用的。未注释的代码是我认为在上一篇文章中被描述为解决方案的代码。感谢有人可以提供修复此代码或更好地构建应用程序的建议,如果这是我需要做的。
(function (angular) {
angular
.module('app',['ngResource', 'ui.router','xeditable', 'inputDropdown'])
.config(function($logProvider, $stateProvider, $locationProvider, $urlRouterProvider ){
// var app = angular.module('app',['ngResource', 'ui.router','xeditable', 'inputDropdown']);
// angular.module('app').config(function($logProvider, $stateProvider, $locationProvider, $urlRouterProvider ){
$logProvider.debugEnabled(true);
var routeRoleChecks = {
admin: {auth: function(flAuth){
return flAuth.authorizeCurrentUserForRoute('admin')
}},
user: {auth: function(flAuth){
return flAuth.authorizeAuthenticatedUserForRoute()
}}
};
$locationProvider.html5Mode({
enabled: true,
requireBase: false, //required to specify base of application in our HTML
rewriteLinks: true //Angular will rewrite URLs as necessary (add# to older browsers)
});
$stateProvider
.state('home', {
url: '/',
views: {
'content-header': {
templateUrl: '/app/main/main-header',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
},
'content-banner': {
templateUrl: '/app/main/main-carousel',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
},
'content-main': {
templateUrl: '/app/games/game-searchList',
controller: 'flGameSearchButtonCtrl',
//controllerAs: 'games:id',
caseInsensitiveMatch: true
},
'content-left': {
templateUrl: '/app/games/game-menu-left',
controller: 'flGameSearchButtonCtrl',
//controllerAs: 'games:id',
caseInsensitiveMatch: true
},
'content-right': {
templateUrl: '/app/games/game-menu-right',
controller: 'flGameSearchButtonCtrl',
//controllerAs: 'games:id',
caseInsensitiveMatch: true
},
'content-footer': {
templateUrl: '/app/main/main-footer',
controller: 'flMainCtrl',
caseInsensitiveMatch: true
}
}
})
$urlRouterProvider.otherwise('home');
});
angular.module('app').run(function($rootScope, $location){
$rootScope.$on('$stateChangeError', function(evt, current, previous, rejection){
if (rejection === 'not authorized'){
$location.path('/');
}
});
});
})(window.angular);