简体   繁体   中英

AngularJS show only filtered elements on ng-repeat

I've got a simple ng-repeat with a simple search filter.

My question is how can i show elements of this list only if filter is set ??

I want the list be empty when the search input contains no value !!

I can't get it work, all the items are displayed if search is filter.

Here the html :

<input type="search" class="form-control" placeholder="Rechercher" data-ng-model="search" />

<div data-ng-repeat="departement in departements | filter:search">
</div>

Here departements objects !

$scope.depatements = [
    {"codeDept": "01", "libelleDept": "D1", "libelleRegion":"R1", "codeRegion": "04"},
    {"codeDept": "02", "libelleDept": "D2", "libelleRegion":"R2", "codeRegion": "08"},
    {"codeDept": "03", "libelleDept": "D3", "libelleRegion":"R3", "codeRegion":"09"}
];

Really thx to you guys.

如果我理解正确,则需要使用本示例中的功能: http : //plnkr.co/edit/eNHrDSn0tfhJT2xJkVRC?p=preview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM