0

Let's say I have selected an element or set of elements using jQuery like so

$('.container .myelement');

Would it then be possible to determine which directive generated .myelement ?

And as the next step, could I also determine the module it belonged to?

Thanks!

x74x61
  • 423
  • 6
  • 18
  • please see this http://stackoverflow.com/questions/29485719/angularjs-how-to-get-an-attribute-value-from-element-in-which-controller-is-de – Hadi J Jun 12 '16 at 08:32
  • 1
    what is the ultimate goal of finding the directive? It's not normal practice to use jQuery to manipulate Angular code. This really feels like an XY question. – Claies Jun 12 '16 at 09:24
  • @Claies I'm just selecting a node using jQuery as an example, I could also have done it using document.getElementById() (without the jquery wrapper). My point is that, once a node is selected, how can I find the directive and/or module? I need to scan a page that was generated by angular modules, and then generate an error report detailing all the errors and their originating directives/modules. – x74x61 Jun 12 '16 at 10:04
  • 2
    This still feels like an XY problem. What "errors" are you scanning for? – Claies Jun 12 '16 at 10:11
  • @Claies For example, I will scan the page to make sure that the headings have a correct hierarchy. So H1 can only have child headings H2, H2's can only have H3's as children and so on. Once the scan is finished, the module developers have to be notified if their module was involved in this error. – x74x61 Jun 12 '16 at 10:44
  • If this is Angular-specific functionality, it should be implemented as Angular module (and it will be a tough job). doing this with jQuery is fundamentally wrong. And you need to patch `angular.module` and nested methods to watch which directives belong to which module, this kind of info isn't available. – Estus Flask Jun 12 '16 at 22:55

1 Answers1

-1
myAppsName = $(".myelement").closest("[ng-app!=''][ng-app]").attr("ng-app")

gives you the the ng-app's name that your element belongs to

myApp = angular.module(myAppsName)

gives you the module with that name

myApp.directive($(".myelement").prop("tagName"))

gives you the directive.

emrhzc
  • 1,347
  • 11
  • 19