How do I get an array of all the elements which share a directive so I can iterate over them and have them do different things to each other?
I have a directive which is used on multiple elements, and depending on the attribute value of each directive which uses restrict: 'A'
, I need the directives to all talk to each other and effect each other in different ways within the link function.
I've tried using:
link : function(scope, elem, attr) {
attr.forEach(function(e, i) {
if(attr[i] === 'menu') {
//do something
} else if (attr[i] === 'scroll') {
//do something else
}
});
}
but I get forEach as an undefined function. I've also tried a simple for loop, but both:
elem.length
and
attr.length
give me undefined.
Note that I don't want to use different directives with different logic because I need each element to actually do something specific to each other element.
I could just use jQuery to select the elements straight up, but that's less than ideal for several reasons.