我用Grunt打包了我的angularjs webapp 一旦部署在Tomcat7上,当我转到localhost:8080时,我收到此错误:
未捕获错误:[$ injector:modulerr]无法实例化模块 myApp由于:
错误:[$ injector:unpr]未知提供者:$ stateProvider http://errors.angularjs.org/1.3.11/ $注射器/ unpr?P0 =%24stateProvider 在http://localhost:8181/myApp/scripts/9bd11555.vendor.js:5:10748
从IDE运行时,webapp运行良好 似乎问题来自咕噜声? '使用严格的';
angular.module('myApp', ['LocalStorageModule', 'tmh.dynamicLocale',
'ngResource', 'ngCookies', 'pascalprecht.translate', 'ngCacheBuster', 'ngTable',
'ngSanitize', 'ui.select','angularValidator','ui.bootstrap','googlechart','ui.bootstrap.showErrors',
'ngActivityIndicator', 'ui.utils','io.dennis.contextmenu'])
.run(function ($rootScope, $filter, $locale, $interval, $location, $http, $templateCache, $state, $translate, Auth, Principal, Language, Ping, ENV, VERSION) {
$rootScope.ENV = ENV;
$rootScope.VERSION = VERSION;
$locale.NUMBER_FORMATS.GROUP_SEP = ' ';
$rootScope.$on('$stateChangeStart', function (event, toState, toStateParams) {
$rootScope.toState = toState;
$rootScope.toStateParams = toStateParams;
if (Principal.isIdentityResolved()) {
Auth.authorize();
}
// Update the language
// Language.getCurrent().then(function (language) {
// $translate.use('fr');
// });
});
$rootScope.pingServer = $interval(function(){
Ping.get();
}.bind($rootScope), 600000);
$rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
$rootScope.previousStateName = fromState.name;
$rootScope.previousStateParams = fromParams;
});
$rootScope.back = function() {
// If previous state is 'activate' or do not exist go to 'home'
if ($rootScope.previousStateName === 'activate' || $state.get($rootScope.previousStateName) === null) {
$state.go('home');
} else {
$state.go($rootScope.previousStateName, $rootScope.previousStateParams);
}
};
$rootScope.convertDate = function(dateDisplay){
if (dateDisplay!=null){
var day=dateDisplay.substring(0,2);
var month=dateDisplay.substring(2,4);
var year="20"+dateDisplay.substring(4,6);
return $filter('date')(new Date(year,month-1,day), 'yyyy-MM-dd');
} else return null;
}
$rootScope.displayDate = function(myDate){
if (myDate!=null){
var day = myDate.substring(8,10);
var month = myDate.substring(5,7);
var year = myDate.substring(2,4);
return day+month+year;
}else return null;
}
})
.config(function ($stateProvider, $provide, $urlRouterProvider, $httpProvider, $locationProvider, $translateProvider, tmhDynamicLocaleProvider, httpRequestInterceptorCacheBusterProvider) {
//enable CSRF
$httpProvider.defaults.xsrfCookieName = 'CSRF-TOKEN';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRF-TOKEN';
//Cache everything except rest api requests
httpRequestInterceptorCacheBusterProvider.setMatchlist([/.*api.*/, /.*protected.*/], true);
$urlRouterProvider.otherwise('/');
$stateProvider.state('site', {
'abstract': true,
views: {
'navbar@': {
templateUrl: 'scripts/components/navbar/navbar.html',
controller: 'NavbarController'
}
},
resolve: {
authorize: ['Auth',
function (Auth) {
return Auth.authorize();
}
],
translatePartialLoader: ['$translate', '$translatePartialLoader', function ($translate, $translatePartialLoader) {
$translatePartialLoader.addPart('global');
$translatePartialLoader.addPart('language');
return $translate.refresh();
}]
}
});
// Initialize angular-translate
$translateProvider.useLoader('$translatePartialLoader', {
urlTemplate: 'i18n/{lang}/{part}.json'
});
$translateProvider.preferredLanguage('en');
$translateProvider.useCookieStorage();
tmhDynamicLocaleProvider.localeLocationPattern('bower_components/angular-i18n/angular-locale_{{locale}}.js');
tmhDynamicLocaleProvider.useCookieStorage('NG_TRANSLATE_LANG_KEY');
$provide.decorator('datepickerPopupDirective', function ($delegate) {
var directive = $delegate[0];
var link = directive.link;
console.log(directive);
directive.compile = function () {
return function (scope, element, attrs) {
link.apply(this, arguments);
element.mask("99-99-99");
};
};
return $delegate;
});
})
答案 0 :(得分:1)
您已使用Implicit Annotation
依赖注入,这种方式在您缩小应用时无效。 https://docs.angularjs.org/guide/di
您可以通过这种方式来定义配置或控制器,以确保它在缩小时正常工作
.run(['$rootScope', '$filter', '$locale', '$interval', '$location' ..., function ($rootScope, $filter, $locale, $interval, $location, ...) {
// do something
}])
.config(['$stateProvider', '$provide', '$urlRouterProvider', '$httpProvider' ..., function ($stateProvider, $provide, $urlRouterProvider, $httpProvider ...) {
// do something
}]);