How to filter data from a textbox in angularjs

** Hi I am filtering array data from a textbox but the code is not working as expected. Can anyone help me. Back side data

 self.AdminLineDetails = function(data) {
   $scope.details = [];
   $scope.details = data.GoalData;
   console.log(data);
 }
      

<div class="row">
  <div class="col-md-12">
    <input ng-model="query" type="text" class="form-control" placeholder="Filter by name or number">
  </div>
  <div>
    <tbody>
      <tr ng-repeat="detail in details|filter:query">
        <td><a href="#">{{detail.firstName}}</a>
        </td>
        <td><a href="#">{{detail.lastName}}</a>
        </td>
        <td><a href="#">{{detail.mdn}}</a>
        </td>
      </tr>

    </tbody>
  </div>
      

Run code


**

0


source to share


2 answers


<input type="text" ng-model="search">
<ul ng-repeat="oneauth in authorisations[0]">
    <li ng-repeat="entry in oneauth | nameFilter:search">{{entry.auth.name}}</li>
</ul>

      

Js

var app = angular.module('myapp', [], function () {});

app.controller('AppController', function ($scope) {    
    $scope.authorisations = [{
        "authorisations":[
        {
            "auth":{
                "number":"453",
                "name":"Apple Inc."
            }
        },
        {
            "auth":{
                "number":"123",
                "name":"Microsoft Inc."
             }
        }]
    }];
});

app.filter('nameFilter', function(){
    return function(objects, criteria){
        var filterResult = new Array();
        if(!criteria)
            return objects;

        for(index in objects) {
            if(objects[index].auth.name.indexOf(criteria) != -1) // filter by name only
                filterResult.push(objects[index]);
        }
        console.log(filterResult);
        return filterResult;  
    }    
});

      



Check this sample

http://jsfiddle.net/yctchgnk/

0


source


You can tell which property you are trying to filter by, do something like



 <tr ng-repeat="detail in details|filter: {firstName: query}">

      

+1


source







All Articles