Title: Feature Request: Programmatically add directives to another directive's elements before they get compiled. · Issue #6950 · angular/angular.js · GitHub
Open Graph Title: Feature Request: Programmatically add directives to another directive's elements before they get compiled. · Issue #6950 · angular/angular.js
X Title: Feature Request: Programmatically add directives to another directive's elements before they get compiled. · Issue #6950 · angular/angular.js
Description: I ran into an issue. So far as I know, Angular doesn't have a mechanism by which to address it easily. http://ngmodules.org has some awesome modules. They are really easy to use, but if they don't expose any events to you, then you're ou...
Open Graph Description: I ran into an issue. So far as I know, Angular doesn't have a mechanism by which to address it easily. http://ngmodules.org has some awesome modules. They are really easy to use, but if they don't ...
X Description: I ran into an issue. So far as I know, Angular doesn't have a mechanism by which to address it easily. http://ngmodules.org has some awesome modules. They are really easy to use, but if they do...
Opengraph URL: https://github.com/angular/angular.js/issues/6950
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Request: Programmatically add directives to another directive's elements before they get compiled.","articleBody":"I ran into an issue. So far as I know, Angular doesn't have a mechanism by which to address it easily.\n\nhttp://ngmodules.org has some awesome modules. They are really easy to use, but if they don't expose any events to you, then you're out of luck if you don't want to actually modify the 3rd party module's source code.\n\nWhat if Angular had an easy way to attach directives to the element of another directive `programmatically` (before it and any sub-templates get compiled) so that one could use third party directives and not worry if they've exposed any useful features like like event handling mechanism (e.g. they don't use ngClick on any elements)?\n\nFor example, here's an example:\n\nSuppose we use someone's `awesomeDirective`.\n\n``` html\n\u003cdiv data-awesome-directive=\"awesome.data\">\u003c/div>\n```\n\nThis nice directive generates some type of awesome HTML widget with HTML that is defined in the 3rd party source code, perhaps a twitter feed, a profile badge, or something else awesome, but the author of the directive did not include any way to handle click events, etc!\n\nWe could step away from Angular, and use jQuery to make a click handler like\n\n``` javascript\n$(\"#awesomeWidget\").on(\"click\", function() {/* ... */});\n```\n\nbut we don't want to leave the world of Angular awesomeness!\n\nPerhaps, a new addition to the `Module.directive` API can be added to Angular so one can add a directive to any other directive's elements, like so:\n\n``` javascript\nangular.element(document).ready(function() {\n\n // create your app with a dependency on a 3rd party module.\n var myApp = angular.module(\"myApp\", [\"awesomeModuleContainingAwesomeDirective\"]);\n\n // the 3rd party module contains an awesomeDirective.\n\n // create a custom directive:\n myApp.directive(\"customDirective\", function() {\n return { // set up directive properties like normal.\n restrict: \"A\",\n scope: {/* ... */},\n // etc...\n };\n });\n\n // attach the custom directive to the elements of another directive:\n myApp.directive(\"awesomeDirective\") // get the directive.\n .attachDirective(\".elements\", \"customDirective\");\n\n // the first argument to attachDirective() is a standard jQuery selector.\n // internally, Angular would use jQuery's .find(\".element\")\n\n // add an already-existing directive to the elements of another directive:\n var awesomeDirective = myApp.directive(\"awesomeDirective\"); // gets the directive.\n awesomeDirective.attachDirective(\".otherElements\", \"ngCloak\");\n\n // use a third argument for directives that accept an attribute expression:\n awesomeDirective.attachDirective(\"#oneElement\", \"ngClick\", \"count = count + 1\");\n\n angular.bootstrap(document, [\"myApp\"]);\n\n /*\n * This would be absolutely pure awesome.\n */\n});\n```\n\nThis would be a nice way to extend directives that you are using in your app... But what if you want to attach directives to only specific instances of another directive? Then:\n\n``` javascript\n myApp.directive(\"awesomeDirective\") // gets the directive.\n .attachDirective([\".rootElements\", \".elements\"], 'ngClick', \"count = count + 1\");\n // ^ still no more than 3 arguments\n```\n\nThe first argument in this case is an array. The first element in the array tells Angular that we wish to attach our directive to elements matching the `awesomeDirective` only if those elements are `.rootElements`. All `.rootElements` that match the `awesomeDirective` will then have the `ngClick` directive applied to sub elements of the class `elements` using jQuery's `.find('.elements')`.\n\nAngular could benefit from something like this! And it would not only be useful for event handling that 3rd party modules haven't exposed, but for augmenting 3rd party directives with all sorts of other functionality.\n","author":{"url":"https://github.com/trusktr","@type":"Person","name":"trusktr"},"datePublished":"2014-04-02T08:35:05Z","url":"https://github.com/angular/angular.js/issues/6950"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:86256eac-c021-07cb-c283-fe07b002cc70 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D2B0:1E6AC8:223D22:307B18:6B0468AC |
| html-safe-nonce | e2c2afaee481c52835aaa281905145283d85f6eda741598d548fa4883454e3ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMkIwOjFFNkFDODoyMjNEMjI6MzA3QjE4OjZCMDQ2OEFDIiwidmlzaXRvcl9pZCI6IjU4MDExMDUzNzA5MzIwNzg3NjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0b77c996a5b843f86df928cb7f1f0f40e048f8d89a63f9931b128dc246a43b90 |
| hovercard-subject-tag | issue:30668395 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular.js/6950/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8b9068adfb7d6a9bc9f9e008d4779544de7bfa77ae0b93a095ec0e134abbe9db/angular/angular.js/issues/6950 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8b9068adfb7d6a9bc9f9e008d4779544de7bfa77ae0b93a095ec0e134abbe9db/angular/angular.js/issues/6950 |
| og:image:alt | I ran into an issue. So far as I know, Angular doesn't have a mechanism by which to address it easily. http://ngmodules.org has some awesome modules. They are really easy to use, but if they don't ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trusktr |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular.js git https://github.com/angular/angular.js.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 460078 |
| octolytics-dimension-repository_nwo | angular/angular.js |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 460078 |
| octolytics-dimension-repository_network_root_nwo | angular/angular.js |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width