1

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: function($http) {
     return authUser;
}

Also I can't find any valid example for using $http inside provider. Inside service/factory $http work fine, but I need to prepare data in provider from config function.

Darien Fawkes
  • 3,023
  • 7
  • 24
  • 35

1 Answers1

0

Services, factory & value aren't available at config phase by design.

You could do it in run()

app.run(['userData', function(userData) {

    userData.checkUser();
});
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
charlietfl
  • 170,828
  • 13
  • 121
  • 150