Monday, April 6, 2015

Decorators in AngularJS, $provide.decorator

$provide.decorator if defined in config section of the application code and modifies original object which is passed as $delegate argument into decorator.

Here is set of examples giving better view on a powerful feature of decorators, available in AngularJS:

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