Reputation: 509
This is my provider.
App.provider('cloudinaryDetails', function(CloudinaryProvider){
function setCloudinaryDetails(cloudinaryDetails){
CloudinaryProvider.configure({
cloud_name: cloudinaryDetails.cloud_name,
api_key: cloudinaryDetails.api_key
});
}
this.$get = function($http){
return {
initialize: function(){
return $http.get('path/to/api').then(function(response){
setCloudinaryDetails(response.data);
});
}
};
};
});
I am calling the initialize function in config module
App.config(function(cloudinaryDetailsProvider){
cloudinaryDetailsProvider.initialize();
});
Console Error:
[$injector:modulerr] Failed to instantiate module App due to: TypeError: cloudinaryDetailsProvider.initialize is not a function
Upvotes: 1
Views: 604
Reputation: 1437
You are injecting the cloudinaryDetailsProvider
"provider" but initialize
is not defined on the provider, it is defined on the instance.
To get a reference to the cloudinaryDetails
"instance", create a run block and inject the instance instead of the provider.
App.run(function(cloudinaryDetails){
cloudinaryDetails.initialize();
});
See AngularJS docs for an explanation on how providers work
Upvotes: 0