Shane Shane - 2 months ago 19
AngularJS Question

input:not([type="checkbox"]) not working in angular test

Below is my compiled template in beforeEach function

template = '<form name="configForm">' +
'<input type="number"/>' +
'<input type="checkbox"/>' +
'<input type="text"/>' +
'<div class="form-error" ng-show="configForm.$error.max">Error</div>' +
element = angular.element(template);
element = $compile(element)($scope);

Why is below find method returning me empty results?

var dirElementInput = element.find('input:not([type="checkbox"])');

But when i use it like this, it works:

var dirElementInput = element.find('input');

Object{0: <input type="number">, 1: <input type="checkbox">, 2: <input type="text">, length: 3}

LOG: 3


The jQueryLite that Angular uses, the find() method is limited to finding by tag name, so you cannot use :not here like you would in the full jQuery library....

An alternative would be to write a small method to filter the input types.

For reference, here's the Angular Documentation on find().