Monday, 18 April 2016

filter in angular

filter:

Select a subset of items from an array.

ex:
$scope.lists = [{name:'sai',company: 'CTS'},{name:'kiran',company: 'cognizant'},{name:'sai kiran',company: 'cognizant'},{name:'sai krishna',company: 'we'}]

task 1:

<label>Search: <input ng-model="searchText"></label> (searches any field)
<ul>
<li ng-repeat="a in lists | filter:searchText"> {{a.name}}</li>
</ul>

task2:

<label>Search By Name: <input ng-model="name"></label>
<ul>
<li ng-repeat="a in lists | filter: {name: name}">{{a.name}}</li>
</ul>

task3:
<input ng-model="search.$"> (searches with any field(i.e, name/ company))
<input ng-model="search.name"> (searches with name field)
<input ng-model="search.company"> (searches with company field)

<ul>
<li ng-repeat="a in lists | filter: search ">{{a.name}}</li>
</ul>

task4: (case scensitive filtering)

<ul>
<li ng-repeat="a in lists | filter: search : true">{{a.name}}</li>
</ul>

No comments:

Post a Comment