<div ng-repeat="city in cities">
<div>city: {{city}}</div>
<div ng-repeat="contact in contacts | filter:selectItems(city)">
contact: {{contact.name}}
</div>
<hr>
</div>
angular.module("myApp", [])
.controller("MyCtrl", function ($scope) {
$scope.selectItems = function (item, city) {
return item.city === city;
};
});
上述代码不起作用。因为在filter filter 筛选函数 selectItems 中有第二个参数city。那么在这种情况下,该怎样以正式的方式在筛选函数中使用第二个参数呢?或者说,Angular是否允许在筛选函数中添加第二个参数?
相关分类