George Bora
George Bora

Reputation: 1650

Searching for children elements with a particular directive AngularJS?

I am writing a directive with AngularJS, the directive is restricted as a attribute, which seeks to manipulate some of the child elements of the element.

So far I'm selecting the elements I want to work with in this manner:

var subMenus = angular.element(element.children()[1]);

Which obviously is bad as I could very easily wind up getting other unexpected elements.

I've also tried selecting elements with a particular directive:

var subMenus = angular.element('[imp-drop-sub]');

This results in selecting the elements which I want plus other elements which have the directive but are not children of the element I want to work with.

Is there some selector which allows me to do both, select those with the particular directive (imp-drop-menu) but only from the children elements ?

Using jQuery is possible but the manipulation must be done from a angular directive.

Upvotes: 0

Views: 543

Answers (1)

Zhonk
Zhonk

Reputation: 634

Unfortunatly angulars jqlite (https://docs.angularjs.org/api/ng/function/angular.element) doesn't support children() with selectors. And also find is very limited.

jQuery can, so that would a solution: jQuery(element).children('[imp-drop-sub]');

The other method would be, to call children() first. Then iterate/foreach through the collection and check if the directive is there or not

Upvotes: 1

Related Questions