0

I have seen this answer of question Extend existing service in angular where concept of decorator in angularjs is doing right things for the same

app.config(function($provide) {
  $provide.decorator('growl', function($delegate) {
    $delegate.add = function(message, type) {
      // implementation for add.
    };
    return $delegate;
  });
});

but my question is

Is decorator in AngularJS the best way to extend the existing service?

Or there are some other functionality related to extend existing service in AngularJS?

Community
  • 1
  • 1
Gaurav Kumar Singh
  • 1,550
  • 3
  • 11
  • 31
  • There are other ways: mixings, extend underlaying class, delegation and composition of service (not quite extension, but achieves same goals). – dfsq May 09 '17 at 15:43
  • Depending on your scenario you perhaps can find a different approach (as pointed on the previous comment) but, speaking about angularjs, it's very much attached to its architecture so it's a little hard to escape from what angularjs gives you. Therefore, I believe decorator is the way to go. – lenilsondc May 09 '17 at 15:48
  • Here is an alternative to `decorator` http://stackoverflow.com/questions/15293943/how-can-i-extend-a-service – lenilsondc May 09 '17 at 16:01

0 Answers0