Javascript 常量在一个服务中未定义,但在另一个服务中有效
我有一个愚蠢的问题。我为我的应用程序定义了一个常量。我将它注入两个不同的服务Javascript 常量在一个服务中未定义,但在另一个服务中有效,javascript,angularjs,undefined,constants,Javascript,Angularjs,Undefined,Constants,我有一个愚蠢的问题。我为我的应用程序定义了一个常量。我将它注入两个不同的服务Auth和Profile。在Auth中,它就像一个符咒。在'Profile'中,它是未定义的。看不出我在这里遗漏了什么 auth.service.js: (function() { 'use strict'; angular.module('App') .factory('AuthService', AuthService); AuthService.$inject = ['$http
Auth
和Profile
。在Auth
中,它就像一个符咒。在'Profile'中,它是未定义的。看不出我在这里遗漏了什么
auth.service.js
:
(function() {
'use strict';
angular.module('App')
.factory('AuthService', AuthService);
AuthService.$inject = ['$http', '$q', '$window', 'API_URL'];
function AuthService($http, $q, $window, API_URL) {
//API_URL works
}
})();
(function() {
'use strict';
angular.module('App')
.factory('ProfileService', ProfileService);
ProfileService.$inject = ['$http', '$q', 'API_URL'];
function ProfileService($http, $q, $window, API_URL) {
//API_URL is undefined
}
})();
profile.service.js
:
(function() {
'use strict';
angular.module('App')
.factory('AuthService', AuthService);
AuthService.$inject = ['$http', '$q', '$window', 'API_URL'];
function AuthService($http, $q, $window, API_URL) {
//API_URL works
}
})();
(function() {
'use strict';
angular.module('App')
.factory('ProfileService', ProfileService);
ProfileService.$inject = ['$http', '$q', 'API_URL'];
function ProfileService($http, $q, $window, API_URL) {
//API_URL is undefined
}
})();
app.constants.js
(function() {
'use strict';
angular.module('App')
.constant('API_URL','/api/v1/');
})();
感谢您的帮助。您的
ProfileService
功能没有注入窗口,请将其删除或添加
ProfileService.$inject = ['$http', '$q', '$window', 'API_URL'];
// ^^^^^^^^^
function ProfileService($http, $q, $window, API_URL) {
}
现在我可以上吊了。谢谢