ng-repeat :filter by single field

后端 未结 12 2302
栀梦
栀梦 2020-11-22 10:06

I have an array of products that I\'m repeating over using ng-repeat and am using

<
12条回答
  •  萌比男神i
    2020-11-22 10:58

    You can filter by an object with a property matching the objects you have to filter on it:

    app.controller('FooCtrl', function($scope) {
       $scope.products = [
           { id: 1, name: 'test', color: 'red' },
           { id: 2, name: 'bob', color: 'blue' }
           /*... etc... */
       ];
    });
    

    This can of course be passed in by variable, as Mark Rajcok suggested.

提交回复
热议问题