[英]How use inside common provider $http in Angular 1.4?
I try to use common provider and in angular app config function set data in provider. 我尝试使用通用提供程序和角度应用程序配置功能设置提供程序中的数据。
.provider('userData', function() {
var authUser = {};
return {
checkUser: function() {
// wish to able use $http here for request to get data from service
// save all data into 'authUser' object
// $get return 'authUser' object
},
getCookie: function(value) {
// wish to able use $http here
},
$get: function() {
// only for return object
return authUser;
}
}
})
app.config(['userDataProvider', function(userDataProvider) {
userDataProvider.checkUser();
});
.controller('headerCtrl', ['$scope', 'userData', '$http', function($scope, userData, $http) {
// use inside all controllers/directives 'userData'
});
I try to use $http as parameter in $get function -> not working: error: 我尝试在$ get函数中使用$ http作为参数 - >不工作:错误:
$get: function($http) {
return authUser;
}
Also I can't find any valid example for using $http inside provider. 此外,我找不到任何有效的使用$ http内部提供程序的示例。 Inside service/factory $http work fine, but I need to prepare data in provider from config function.
内部服务/工厂$ http工作正常,但我需要从配置函数准备提供程序中的数据。
Service
s, factory
& value
aren't available at config phase by design. 在配置阶段,设计不提供
Service
, factory
和value
。
You could do it in run()
你可以在
run()
做到这一点
app.run(['userData', function(userData) {
userData.checkUser();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.