D
D
Demigodd2018-12-04 12:14:57
JavaScript
Demigodd, 2018-12-04 12:14:57

How to get a filtered array?

<input ng-model="this.searchText" type="text">

<div ng-repeat="obj in this.objects | filter: this.searchText">
  <p> {{obj.name}} </p>
</div>

<div ng-if="this.objectIsEmpty()">
  Objects is Empty :(
</div>

this.searchText = '';
this.objects = [{id: 1, name: 'test1'}, {id: 2, name: 'test2'}, {id: 3, name: 'test3'}]

function objectIsEmpty() {
 return !this.objects.length;
}

There is such a code, for example, if the user has displayed such a name that is not in the object, then it will not be shown in the div`e.
And there is a function that always returns the length of the Objects array , and if the length of the array is 0 , then it shows the message Objects is Empty :( .
But the problem is that I need to check the already filtered array in the functions.
How can I do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-12-04
@Demigodd

ng-repeat="obj in this.objects | filter: this.searchText as filtered"

ng-if="!filtered.length"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question