0

I'm using angular growl service (angular-growl), and i need one method to add growl with specific type, e.g.

.controller('Controller', ['$scope', 'growl', function ($scope, growl) {
     growl.add("Message", "INFO");
}

is it possible to append new method to growl service (or append method to any service) when angular start process?

kris14an
  • 741
  • 7
  • 24

1 Answers1

2

Basically you can use the concept of Angular decorator to extend the existing service. This is done through $provide.decorator. An implementation would look something like this:

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

Read more about it in this SO post What are "decorators" and how are they used?

Community
  • 1
  • 1
Chandermani
  • 42,589
  • 12
  • 85
  • 88