D Nagy D Nagy - 1 month ago 9
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
$scope.contracts
based on the name of a partner in HTML?
e.g.
ng-repeat="contract in contracts | filter : {partner: {name: 'John'}}"
. Here I should get the first contract but I have an empty array.

Answer

Its typo partner should be partners inside filter.

ng-repeat="contract in contracts | filter : {partners: {name: 'John'}}"