Reputation: 3104
For some reasons, I want to pass masterapp.value ('mastervalue' , 'XYZ') to provider. How to do that ? Below approach throw error.
var masterapp= angular.module('masterapp',[]);
masterapp.value ('mastervalue' , 'XYZ');
masterapp.provider('masterprovider', ['mastervalue', function(mastervalue) {
this.myFn = function() {
return mastervalue;
};
}]);
Upvotes: 0
Views: 93
Reputation: 4045
You need to make it constant if that is fine with you (cannot be changed). So the updated code will be:
var masterapp= angular.module('masterapp',[]);
masterapp.constant('mastervalue' , 'XYZ');
masterapp.provider('masterprovider', ['mastervalue', function(mastervalue) {
this.myFn = function() {
return mastervalue;
};
}]);
Upvotes: 1
Reputation: 128
I'm not sure if .value can be returned like that. Try assigning it first within scope and then using that value to create the function.
this.masterValue = mastervalue;
this.myFun = function(){
return this.masterValue
}
Upvotes: 1