angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Feature Request: angular.decorator as companion to angular.component

Open hannahhoward opened this issue 9 years ago • 3 comments

To facilitate ng 1.x to 2.x migration, ng 1.x should add a new directive helper to mimic Angular 2.0's Directive, in the same way the proposed angular.component #10007 would mimic Angular 2.0's Component. I am proposing calling it "decorator" after the former name it had in NG 2.0, since it's goal would be to decorate an element with behavior and obviously a major change to angular.directive itself would break lots of code. Key features of decorator would be:

  1. no template
  2. defaults to restrict: 'A'
  3. hierarchical injection on the controller -- this is the big one - would only to be able to inject services from the parent component, browser singleton services, and ancestory/parent/child/sibling directives.

I'd propose an api as follows:


angular.decorator('decoratorName', function() {
   return {
     controller: ['$element', 'serviceOnComponent', 'parent:parentElementDirective', 'ancestor:ancestorElementDirective', 'sibling:siblingDirecitve', 'query:childDirectives', DecoratorController],
     bind: {
        'value': 'attribute'
     }
   };
   function DecoratorController($element, serviceOnComponent, parentElementDirective, ancestorElementDirect, siblingDirective, childDirectives) {
     // add some behavior to $element here
   }
});

As an alternative proposal, add the ability to have hierarchical constraints on injection in standard directives, and also add the ability to inject other directives into a directive's controller.

hannahhoward avatar Jul 14 '15 04:07 hannahhoward

angular.decorator() is already taken, so need some other name :D

gkalpak avatar Jul 15 '15 05:07 gkalpak

I think you mean module.decorator?

petebacondarwin avatar Jul 15 '15 13:07 petebacondarwin

Moving to the ice box as I don't think this adds so much value as the component helper

petebacondarwin avatar Jan 08 '16 12:01 petebacondarwin