当在输入中输入第一个字母时,结果显示包含该字母的所有字符串,而不是以字母开头的结果。是否有其他类型的内置过滤器或属性?
<input ng-model="search.RegionName">
<div class="item" ng-repeat="region in DividedRegionList | filter:search:strict" >
答案 0 :(得分: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>