2015-01-31 86 views
0

在輸入中輸入第一個字母時,結果顯示包含該字母的所有字符串,而不是以字母開頭的結果。是否有其他類型的內置過濾器或屬性?角度搜索篩選結果​​

<input ng-model="search.RegionName"> 
<div class="item" ng-repeat="region in DividedRegionList | filter:search:strict" > 

回答

1

試試這個:

http://plnkr.co/edit/gcVYfZXTqsDU1Z7REU2I?p=preview

var app = angular.module('filterSample', []); 
app.controller('filterCtrl', function ($scope) { 

    $scope.data = { 
    messages: ['first', 'second', '3rd', 'fourth', 'fifth'] 
    } 

    $scope.startsWith = function (actual, expected) { 
    var lowerStr = (actual + "").toLowerCase(); 
    return lowerStr.indexOf(expected.toLowerCase()) === 0; 
    } 
}); 

而且模板:

<ul border="1px" ng-repeat="msg in data.messages | filter:search:startsWith"> 
     <li>{{msg}}</li> 
    </ul>