So I have a simple ul that ng-repeats li elements from the external source gathered with a promise. I also have a search input that filters these elements, and I would like for the ul to hide when it contains no more elements that satisfy the search.
I made this directive, but its not working:
.directive('predictive', function() {
return {
restrict: 'A',
link: function(scope, element) {
console.log(element);
if (!$(element).children("li").length) {
$(element).hide();
}
}
}
});
But the directive hides everything because it applies too fast, before the service that gets the data fills the list with li's.
Anything I can do about it?
EDIT: the markup
<input type="text" ng-model="predictiveSearch"></input>
<ul ng-repeat="(key, option) in Service1.predictive" predictive>
<span><b>{{key}}</b></span>
<li ng-repeat="option in option | filter:predictiveSearch">
<a href="" ng-click="handlePredictiveSelection(option)">{{option}}</a>
</li>
</ul>
`
– charlietfl Jun 15 '16 at 09:47