<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;
};
});
它不起作用。因爲在濾波器過濾功能中有一個參數城市。但在這種情況下,在過濾器過濾器函數中使用參數的正確語法是什麼?或者在過濾器過濾器函數中允許一個參數?在AngularJS中,如何在過濾器函數中使用參數?
什麼是在$ scope.selectItems =函數(項目,市)項目{}您有沒有通過你稱之爲的項目。 –
我認爲第一個參數(item)是自動傳遞給函數的,所以我只需要手動傳遞第二個參數。 – Benson
這是一個很好的資源:https://scotch.io/tutorials/building-custom-angularjs-filters –