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

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

Open
hannahhoward opened this issue Jul 14, 2015 · 3 comments
Open
Milestone

Comments

@hannahhoward
Copy link
Contributor

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.

@gkalpak
Copy link
Member

gkalpak commented Jul 15, 2015

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

@petebacondarwin
Copy link
Contributor

I think you mean module.decorator?

@petebacondarwin petebacondarwin added this to the Backlog milestone Jul 15, 2015
@petebacondarwin petebacondarwin modified the milestones: 1.5.x - migration-facilitation, Backlog Sep 22, 2015
@petebacondarwin petebacondarwin modified the milestones: Ice Box, 1.5.x - migration-facilitation Jan 8, 2016
@petebacondarwin
Copy link
Contributor

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

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants