ng-repeat with track by and filter and orderBy not working

后端 未结 2 803
萌比男神i
萌比男神i 2020-12-30 23:35

I have this code.

http://jsfiddle.net/0tgL7u6e/

JavaScript

var myApp = angular.module(\'myApp\',[]);

function MyCtrl($scope         


        
相关标签:
2条回答
  • 2020-12-31 00:08

    To use tracking with filters, the track by expression has to be added after the filter.

    <p ng-repeat="contact in contacts | orderBy: 'name' | filter: nameFilter  track by $index">{{ contact.name }}</p>
    

    Here is the working fiddle

    0 讨论(0)
  • 2020-12-31 00:12

    you have to change the code to the following one

    <div ng-controller="MyCtrl">
        <div><input type="text" ng-model="nameFilter" placeholder="Search..." /></div>
        <p ng-repeat="contact in contacts  | orderBy: name | filter: nameFilter track by $index ">{{ contact.name }}</p>
    </div>
    
    0 讨论(0)
提交回复
热议问题