简体   繁体   中英

angular filter doesn't work

Trying to make filter through mass of objects.

<input type="text" ng-model="search.name">
<input type="text" ng-model="search.contact">
<input type="text" ng-model="search.company_phone">
<input type="text" ng-model="search.address">
<div class="matrix_container">
<div class="matrix">

    <div ng-repeat="row in search_result track by $index | filter:search">
        <div class="properties">{{row.name}}</div>
        <div class="properties">{{row.contact}}</div>
        <div class="properties">{{row.company_phone}}</div>
        <div class="properties">{{row.address}}</div>

    </div>
</div>

There is a message about a mistake

Error: [filter:notarray] http://errors.angularjs.org/1.6.3/filter/notarray?p0=0

typeof search_result is obejct, but as I know in js object=array, no?

console.log(search_result)

在此处输入图片说明

track by $index should be applied at the last, So it should be like:

ng-repeat="row in search_result | filter:search track by $index"

See this example fiddle

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