This is example of searching users JSON data based on user's input and showing them in clean way. Click here to know how text box with reset button (Clear field) works


Find below Users info in JSON format
$scope.userData = [
            {"id":"1", "name":"Srinivas Dasari", "place":"Chennai", "pic":""},
            {"id":"2", "name":"Srinivas Tamada", "place":"Atlanta", "pic":""},
            {"id":"3", "name":"Sri Harsha", "place":"Hyderabad", "pic":""},
            {"id":"4", "name":"Lokesh Raghuram", "place":"Chennai", "pic":""},
            {"id":"5", "name":"Bala Ganesh", "place":"Chennai", "pic":""},
            {"id":"6", "name":"Arun kumar", "place":"Chennai", "pic":""}


By using filter, we can search JSON data
<div class="slinput" ng-init="">
    <i class="fa fa-search left-icon"></i> 
    <input placeholder="Search here" ng-model="searchInputVal"/> 
    <i ng-class="{'fa' : true, 'fa-close' : true, 'right-icon' : true, active : (searchInputVal.length > 0)}" ng-click="searchInputVal = ''"></i>
<div class="media user" ng-repeat="user in userData | filter:searchInputVal">
      <div class="media-left">
        <a href="#">
        <img class="media-object" src="{{user.pic}}" alt="...">
      <div class="media-body">
        <h4 class="media-heading">{{}}</h4>
The same functionality implemented with jQuery with more lines of code, you can check it here

1 comment:


Popular Posts