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
  • 2,793
  • 6
  • 22
  • 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
  • 130,886
  • 22
  • 223
  • 289
charlietfl
  • 169,044
  • 13
  • 113
  • 146