WebWanderer
WebWanderer

Reputation: 10887

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!

Upvotes: 3

Views: 56

Answers (1)

Emir Marques
Emir Marques

Reputation: 2687

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();

Upvotes: 2

Related Questions