AngularJS长度过滤器

时间:2018-05-12 08:40:44

标签: angularjs filter

如何在带有ng-option过滤器的选择框中仅显示2个字符长度值?

ng-options="item.NumberValue as item.Title for item in myLists.list1 | filter:{NumberValue.length:2}"

1 个答案:

答案 0 :(得分:0)

你可以这样做:

ng-options="item.NumberValue as item.Title for item in 
    myLists.list1 | filter:3:comparator"

然后在控制器中定义比较器:

$scope.comparator = function (value, size) {
    return value.length === size;
};

请参阅fiddle