Domanda

I want to use the Angular filter on ng-repeat to search in another object, not the object used in the ng-repeat. Can I do that or there is a better way to do that.

Here is a Plunker link.

I want to search in the all_data object not sample_data.

È stato utile?

Soluzione

You can use this trick:

<div ng-init="filteredItems = all_data"/>

<input ng-model="searchText" ng-change="filteredItems = (all_data | filter: searchText)">

At start, filteredItems equals all_data. When input searchText changed, filteredItems changed too.

You can use {{filteredItems}} on the view, and $scope.filteredItems in the controller.

I adjust your plunker, please see it.

Plunker

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top