I am writing a directive in AngularJS
and one of the things I need to do is find all of the controls inside a form and iterate over them.
If jQuery
was loaded I do this:
var inputs = element.find(".ng-invalid,.ng-valid");
inputs.each(function ()
{
var i = $(this);
});
But since it is not loaded and I just have Angular
I can only think to do something like:
var inputs = element.find("input");
//for loop thru this
var selects = element.find("select");
//for loop thru this
//....etc
Is there some better way using jQLite to accomplish this?
If supporting IE7 or older is not a requirement, you can use the querySelectorAll method of Element
:
var controls = element[0].querySelectorAll('.ng-invalid, .ng-valid');
[].forEach.call(controls, function (ctl) {
var c = angular.element(ctl);
...
});