DaveC426913 DaveC426913 - 1 year ago 112
AngularJS Question

Using filter on angular ng-repeat

I am trying to filter to just one store, given the store Id, which is picked in a dropdown.


<tbody data-ng-repeat="store in orderVm.Stores | filter :{store.id=orderVm.Stores.selectedStore.id}">

I don't get how to set up the filter so that it only shows the one store with the specified id.


vm.Stores = json;// from file
vm.Stores.selectedStore = {
id: vm.Stores[0].Id,
name: vm.Stores[0].MarketplaceName


"Id": 1,
"MarketplaceId": 1,
"MarketplaceName": "Etsy"
"Id": 2,
"MarketplaceId": 2,
"MarketplaceName": "Shopify"

The error I get is unexpected%2C%20expecting%20%5B%3A%5D&p2=32&p3=orderVm.Stores%20%7CNaNilter%20%3A%7Bstore.id%3DorderVm.Stores.selectedStore.id%7D&p4=.id%3DorderVm.Stores.selectedStore.id%7D

Answer Source

Simple to filter your data by value:

<tbody data-ng-repeat="store in orderVm.Stores | filter:Vm.Stores.selectedStore.id">

It will get objects with properties have value is Vm.Stores.selectedStore.id. Because name not is a number (id), you can use this filter for it.

To specific filter by value of id:

<tbody data-ng-repeat="store in orderVm.Stores | filter:{Id:Vm.Stores.selectedStore.id}:true">

Syntax: filter:{propertyName:value}:true

true is for exact match.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download