I'm using AngularJS and I'm displaying a list with ng-repeat. What I'm trying to achieve is to filter the list and only show the items that contain the value that the user writes in the input.
I set it up like the example found here but had no success.
HTML:
<div ng-if="result.length > 0">
<input type="text" class="pl-4" ng-model="searchText" placeholder="Search" />
<div class="mt-4 text-left animationIf" ng-repeat="item in result | filter: searchText">
<div>
<span class="text-danger">Name: </span>
<span class="m-0" ng-bind="item.name"></span>
</div>
<div>
<span class="text-danger">Country: </span>
<span class="m-0" ng-bind="item.country"></span>
</div>
<div>
<span class="text-danger">Born: </span>
<span class="m-0" ng-bind="item.born"></span>
</div>
<div>
<span class="text-danger">Surnname: </span>
<span class="m-0" ng-bind="item.surname"></span>
</div>
</div>
</div>
An example of the result object would be like this:
$scope.result = [{
name: "John",
country: "California ",
born: "283 AC",
surname: "Snow"
},{
name: "Michael",
country: "US",
born: "1958",
surname: "Jackson"
}];
If I give at ng-init="$scope.result = 'John'"
the filter works and displays only items that contain 'John' but if I later change the value o the input to 'Michael', it will do nothing. No filter applies.
What am I doing wrong here?