I am trying to find of a way to extend services in angular. I am not sure if angular has a concept of extending or if it merely relies on injection for code reuse. So what I have tried so far are the following
Method 1
myApp.factory('myFactory', function ($http) {
return{
common: function(){
console.log('I am from myFactory');
}
});
myApp.factory('myFactory1', function (myFactory) {
return {
common: myFactory.common
};
});
OR
myApp.factory('myFactory1', function (myFactory) {
return angular.extend(myFactory, {
common: function() {
console.log('I am form Factory1')
}
});
});
Both approaches sort of work OK but my main issue is how to call the parent. i.e. something like this:
in myFactory1
common: function(){
console.log('I am from myFactory1');
this.prototype.common.apply(this, arguments);
}
I want is to print out 'I am from myFactory1', 'I am from myFactory'
Generally Is this supported in angular ? Or should I take a different approach in extending /inheriting functionality?
Thank you