I am attempting to use a common provider in my Angular app's configuration function to set data in the provider.
.provider('userData', function() {
var authUser = {};
return {
checkUser: function() {
// I wish to be able to use $http here for making requests to get data from a service
// Save all data into the 'authUser' object
// $get should return the 'authUser' object
},
getCookie: function(value) {
// I also wish to be able to use $http here
},
$get: function() {
// Used only for returning the object
return authUser;
}
}
})
app.config(['userDataProvider', function(userDataProvider) {
userDataProvider.checkUser();
});
.controller('headerCtrl', ['$scope', 'userData', '$http', function($scope, userData, $http) {
// Utilize the 'userData' inside all controllers/directives
});
I tried using $http as a parameter in the $get function, but it is not working and throws an error:
$get: function($http) {
return authUser;
}
Additionally, I have been unable to find any valid examples of using $http inside a provider. While $http works fine inside a service or factory, I need to prepare data in the provider from a configuration function.