I've the following html list :
<input ng-model="searchValue" />
[...]
<ul>
<li ng-repeat="item in dataset" ng-if="item.contains(searchValue)">{[item.name]}</li>
<li noresult>No result ...</li>
</ul>
I prefer use the ng-if than the ng-repeat filter.
And I want to manage the 'noresult' display with the following directive :
directive('noresult', [
function () {return {
restrict: "A",
link : function (scope, element, attrs) {
scope.$watch(
function () { return element.parent().children().length; },
function (length) {
console.log(length)
if(length == 1){element.show();}
else{element.hide();}
}
);
}
}}]);
When I type something into the input, "console.log" raises each two letters !
Why ? And how can I fix it ?