結合這個偉大的工程:AngularJS數據控制器
<input type="text" class="search" data-ng-model="name"/>
<div class="rf-contact" data-ng-repeat="contact in contacts | filter: name">
<p class="rf-first">{{contact.first_name}} {{contact.last_name}}</p>
</div>
不過,我需要在控制器來實現過濾器:
var contactsController = function ($scope, $filter){
$scope.contacts = contacts;
$scope.filteredContacts = $filter('filter')($scope.contacts, $scope.name);
}
<input type="text" class="search" data-ng-model="name"/>
<div class="rf-contact" data-ng-repeat="contact in filteredContacts">
<p class="rf-first">{{contact.first_name}} {{contact.last_name}}</p>
</div>
與上面的代碼的問題是,數據綁定丟失。當文本字段中的數據發生更改時,不會發生過濾。我是否需要爲控制器中的輸入字段顯式設置事件偵聽器?謝謝。