angular.js
angular.js copied to clipboard
Feature Request: angular.decorator as companion to angular.component
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:
- no template
- defaults to restrict: 'A'
- 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.
angular.decorator()
is already taken, so need some other name :D
I think you mean module.decorator
?
Moving to the ice box as I don't think this adds so much value as the component
helper