service('simperiumBucket', function($localStorage, $rootScope, simperiumCred){
var self = this;
self.make = function(name) {
//here is the code i wish to run
};
$rootScope.$on('authSuccess', function(scope,response){
self.make('first');
});
return {
make: self.make
};
});
Is it possible to call method from inside of service/object?
-
23-07-2023 - |
Question
I'm trying to trigger a service-method from inside the service. I have tried simperiumBucket.make
and this.make
. Neither work.
service('simperiumBucket', function($localStorage, $rootScope, simperiumCred){
$rootScope.$on('authSuccess', function(scope,response){
simperiumBucket.make('first')
});
return{
make: function(name){
//here is the code i wish to run
}
}
}).
How can I trigger the method?
Solution
OTHER TIPS
You will have to reorder your code a bit:
var ret = {
make: function(name){ ... }
};
$rootScope.$on('authSuccess', function(scope,response) {
ret.make('first');
});
return ret;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow