ng-repeat :filter by single field

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

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

<
12条回答
  •  故里飘歌
    2020-11-22 10:38

    Be careful with angular filter. If you want select specific value in field, you can't use filter.

    Example:

    javascript

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

    html

    This will select both, because use something like substr
    That means you want select product where "color" contains string "blue" and not where "color" is "blue".

提交回复
热议问题