Extend Existing Service In Angular
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)
Solution 1:
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?
Post a Comment for "Extend Existing Service In Angular"