D Nagy D Nagy - 1 year ago 54
Javascript Question

Angularjs filter array based on a property which is of type Array

I have an object that looks similar to this:

$scope.contracts = [
name: "contract1",
partners : [{name: "John", age:"21"}, {name: "Peter", age: "33"}]
name: "contract2",
partners : [{name: "George", age:"51"}, {name: "Jack", age: "42"}]

How can I filter
based on the name of a partner in HTML?
ng-repeat="contract in contracts | filter : {partner: {name: 'John'}}"
. Here I should get the first contract but I have an empty array.

Answer Source

Its typo partner should be partners inside filter.

ng-repeat="contract in contracts | filter : {partners: {name: 'John'}}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download