Is there a way I could emulate jQuery's .parents()
method in Angular, without having to actually include jQuery?
The final goal is to get all the parents of a DOM element.
EDIT: Why I need this?
I'm creating a directive (a dropdown-like widget). The dropdown should listen the entire <body>
for clicks and close itself (if it's open) if a click is made outside of the widget's area.
Now, I know how to create a simple directive that would listen for mouse events, like this one:
app.directive('mouseTrap', function() {
return function(scope, elem) {
elem.bind('click', function(event) {
scope.$broadcast('click', { event: event } );
});
};
});
...which I would then use like this: <body mouse-trap .... >
and
$scope.$on('click', function(msg, obj) {
console.log("click!");
});
That is where I need to check if any of the parents of the clicked object is the top-level div of my widget, and if not, close the widget.