常量在一个服务中未定义,但在另一个服务中有效
Constant is undefined in a service but works in another
我对angular有一个愚蠢的问题。我为我的应用定义了一个常量,我把它注入到两个不同的服务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
}
})();
profile.service.js
:
(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) {
}
相关文章:
- Ember服务在注入组件并在计算属性中使用后是未定义的
- 未定义服务
- Http服务工厂将未定义的返回到Angular中的控制器
- 角度服务未定义
- 通过C#向区块链服务发送请求时未定义XMLHttpRequest
- 服务变量分配了数据,但在访问时始终未定义
- 承诺返回未定义的服务
- 从服务返回值时$scope控制器的变量是未定义的
- 提供“角服务”;TypeError:无法读取属性'helloConsole'“未定义”;
- 正在从web服务接收未定义的信息
- Angular 1.5.4服务未定义
- 使用路由的未定义服务控制器
- Web服务返回给javascript的值是未定义的
- 返回未定义的角度服务不是一个函数
- 无法使用服务AngularJS - “无法读取未定义的属性'原型'”
- 服务函数返回未定义
- 类型错误:parsed 在 angularjs 服务单元测试中未定义
- 尽管注入了$http,但它在服务中是未定义的
- 注入控制器时,服务未定义
- 输出JSON数组值时服务未定义