Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: Getting the scope that an element was compiled with

Let's say I have a directive with an incoming attribute of "contextMenuId."

In this directive I now perform:

contextMenu = $('[id*="' + iAttrs.contextMenuId+'"]');

or...

contextMenu = angular.element(document.querySelector('[id*="' + iAttrs.contextMenuId+'"]'))

If these don't do the same thing, I would love it if someone could tell me the difference, but that's separate from my answer.

Now, lets have a look at our contextMenu:

<ul id="exampleContextMenu" context-menu-defs="contextMenuDefs" ></ul>

I would like to access the array contextMenuDefs from the directive I mentioned earlier, yet this is from an entirely different scope that I do not have access to.

Can I somehow get access to the scope that contextMenu was compiled with from within my directive? Thanks!

like image 280
WebWanderer Avatar asked Dec 20 '25 21:12

WebWanderer


1 Answers

You can use for get scope other element:

angular.element("<selector as jquery>")).scope();

In your situation:

var scopeOuther = angular.element('[id*="' + iAttrs.contextMenuId+'"]')).scope();
like image 168
Emir Marques Avatar answered Dec 23 '25 10:12

Emir Marques



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!