{"action":"created","issue":{"url":"https://api.github.com/repos/angular/ngUpgrade/issues/2","labels_url":"https://api.github.com/repos/angular/ngUpgrade/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/angular/ngUpgrade/issues/2/comments","events_url":"https://api.github.com/repos/angular/ngUpgrade/issues/2/events","html_url":"https://github.com/angular/ngUpgrade/issues/2","id":94874854,"number":2,"title":"angular.decorator? / analogue to NG2 Directive","user":{"login":"hannahhoward","id":1450680,"avatar_url":"https://avatars.githubusercontent.com/u/1450680?v=3","gravatar_id":"","url":"https://api.github.com/users/hannahhoward","html_url":"https://github.com/hannahhoward","followers_url":"https://api.github.com/users/hannahhoward/followers","following_url":"https://api.github.com/users/hannahhoward/following{/other_user}","gists_url":"https://api.github.com/users/hannahhoward/gists{/gist_id}","starred_url":"https://api.github.com/users/hannahhoward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hannahhoward/subscriptions","organizations_url":"https://api.github.com/users/hannahhoward/orgs","repos_url":"https://api.github.com/users/hannahhoward/repos","events_url":"https://api.github.com/users/hannahhoward/events{/privacy}","received_events_url":"https://api.github.com/users/hannahhoward/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-14T06:07:01Z","updated_at":"2015-07-15T03:32:15Z","closed_at":null,"body":"cross-posted to https://github.com/angular/angular.js/issues/12342\r\n\r\nA lot has been written about supporting components in ng 1.x -- whether through module.component or through an annotation library. But really components are really only half the story NG 2.0's directive story. The other is a directive to add behavior to an element, simply called a Directive in Angular 2.0. \r\n\r\nTo facilitate ng 1.x to 2.x migration, maybe 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:\r\n1. no template\r\n2. defaults to restrict: 'A'\r\n3. 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.\r\n\r\nI'd propose an api as follows:\r\n\r\nangular.decorator('decoratorName', function() {\r\n   return {\r\n     controller: ['$element', 'serviceOnComponent', 'parent:parentElementDirective', 'ancestor:ancestorElementDirective', 'sibling:siblingDirecitve', 'query:childDirectives', DecoratorController],\r\n     bind: {\r\n        'value': 'attribute'\r\n     }\r\n   };\r\n   function DecoratorController($element, serviceOnComponent, parentElementDirective, ancestorElementDirect, siblingDirective, childDirectives) {\r\n     // add some behavior to $element here\r\n   }\r\n});\r\n\r\nAs 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."},"comment":{"url":"https://api.github.com/repos/angular/ngUpgrade/issues/comments/121476768","html_url":"https://github.com/angular/ngUpgrade/issues/2#issuecomment-121476768","issue_url":"https://api.github.com/repos/angular/ngUpgrade/issues/2","id":121476768,"user":{"login":"timkindberg","id":168046,"avatar_url":"https://avatars.githubusercontent.com/u/168046?v=3","gravatar_id":"","url":"https://api.github.com/users/timkindberg","html_url":"https://github.com/timkindberg","followers_url":"https://api.github.com/users/timkindberg/followers","following_url":"https://api.github.com/users/timkindberg/following{/other_user}","gists_url":"https://api.github.com/users/timkindberg/gists{/gist_id}","starred_url":"https://api.github.com/users/timkindberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timkindberg/subscriptions","organizations_url":"https://api.github.com/users/timkindberg/orgs","repos_url":"https://api.github.com/users/timkindberg/repos","events_url":"https://api.github.com/users/timkindberg/events{/privacy}","received_events_url":"https://api.github.com/users/timkindberg/received_events","type":"User","site_admin":false},"created_at":"2015-07-15T03:32:15Z","updated_at":"2015-07-15T03:32:15Z","body":"Hierarchical injectors seems the better route and leave angular.directive as it is. Then via best practices devs could choose to only use it in a 'decorator' sense. Also I'd love a little more explanation on why hierarchical injectors would be truly needed. Perhaps we could add most of the special injectables (ancestor, parent, sibling, child, descendant) via some smart look-up methods and dom traversal."}}