Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

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

@hannahhoward

Description

@hannahhoward

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions