user12
user12

Reputation: 239

Filtering array of (key,value) in angular js

I am working a piece of code in angular 1.x , where I would like to filter array of key,values.

HTML:

<input type="text" ng-model="cust"> 

<div ng-repeat="customer in customers| filter :cust['name']">
    {{customer["name"]}}
</div>

JS:

$scope.customers = [
    {"name":"Sathish"},
    {"name":"Ankur"},
    {"name":"Bob"},
    {"name":"Mike"},
    {"name":"chris"},
    {"name":"chrom"}
];

Basically I want to filter the array based on name of customer. if I give "ch" in the input text box it should give filter and give chris and chrom.

Upvotes: 0

Views: 361

Answers (1)

juvian
juvian

Reputation: 16068

You want to filter based on cust name but cust is just a string, so not sure what you currently have is doing. Correct way would be :

<div ng-repeat="customer in customers| filter :{name : cust}">

Upvotes: 1

Related Questions