简体   繁体   中英

Using angularJS filter to search in another object

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM