Here is set of examples giving better view on a powerful feature of decorators, available in AngularJS:
- adding a custom method to 3rd party service, by tamakisquare - http://plnkr.co/edit/lj9srM2KXZmwmTxLb1p7?p=preview
- logging time while the async call is performed, using Promise.always - by K. Scott Allen http://odetocode.com/blogs/scott/archive/2013/06/06/decorating-angularjs-services.aspx
- creating more detailed response description, https://egghead.io/lessons/angularjs-provide-decorator
- adding custom method reload method to $state provider - stackoverflow.com/a/23198743/405623
MY_APP.config(function($provide) {
$provide.decorator('DECORATOR_NAME', function($delegate) {
//directly add methods
$delegate.NEW_METHOD = function(...) {
//do stuff
};
//or using object prototype
Object.defineProperty($delegate.prototype, 'NEW_METHOD',
{
get: function() {
//do stuff
}
}); return $delegate;
});
});
});
});
No comments:
Post a Comment