Skip to content Skip to sidebar Skip to footer

How To Filter The Data From Text Box In Angularjs

**Hi,i am filtering the array data from textbox but the code is not working properly can any one help me please.the data from back end **

Solution 1:

You can specify on which property you are trying to filter, do something like

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

Solution 2:

<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/


Post a Comment for "How To Filter The Data From Text Box In Angularjs"