Element from scope?

40 views
Skip to first unread message

Matt Hughes

unread,
Mar 3, 2014, 1:41:17 PM3/3/14
to ang...@googlegroups.com
You can get the scope associated with a given DOM element via:

angular.element(foo).scope(). 

Are you able to do the reverse?  I have the scope, but I want the element associated with it.

Luke Kende

unread,
Mar 4, 2014, 1:40:57 AM3/4/14
to ang...@googlegroups.com
$scope is not associated with just one element if it's in a controller, and if you were using a directive, I do not think you would ask this question.   No, I don't believe there's a way to access a reference to an element from a controller's $scope.

This sounds like bad practice.   What is it you are trying to accomplish that you believe you need an element reference from scope?

Matt Hughes

unread,
Mar 5, 2014, 5:07:29 PM3/5/14
to ang...@googlegroups.com
I am in a directive.  Specifically https://github.com/wix/angular-tree-control/blob/master/angular-tree-control.js.  It's a recursive directive as the name might suggest; it associates data with child scope.  In this particular directive, it is really just element == scope.  They pass the scope around to a bunch of functions and I was hoping to be able to manipulate the associated element node in the same function. 

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/YIU9uby5TuE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Luke Kende

unread,
Mar 5, 2014, 9:48:09 PM3/5/14
to ang...@googlegroups.com
The link function has a reference to the element.  I cannot guess at what you are trying to do, so you'll have to play around to see if you have access to what you want, where you want it.  Good luck!
Reply all
Reply to author
Forward
0 new messages