How to filter results from nested objects in angular

I have the nested objects in my angular like this

{
"name": "John"
"age" : "23"
subjects: [

{
"description":"Math"
"length":"1 month"
},
{
"description":"English"
"length":"1 month"
}


]



}

IN angular the filter works fine with name, age but how can i find those students whose subject description contains Math

The documentation page on filters has an interesting example.

In it, the ng-model of the search box is set to search.$ instead of search. This seems to be a wild card for matching.

Here's a jsFiddle for you. Type whatever into the search box and it will find the matching student.

<input id="txtSearch" type="text" ng-model="search.$" />
<ol>
    <li ng-repeat="student in myData | filter:search">
        {{student.name}}
        {{student.subjects}}
    </li>
</ol>

and the data model looks like this:

$scope.myData = [{
    "name": "Student 1",
        "age": "20",
    subjects: [{
        "description": "Math",
            "length": "1 month"
    }, {
        "description": "English",
            "length": "1 month"
    }]
}, {
    "name": "Student 2",
        "age": "22",
    subjects: [{
        "description": "Economics",
            "length": "1 month"
    }, {
        "description": "English",
            "length": "3 months"
    }]
}, {
    "name": "Student 3",
        "age": "23",
    subjects: [{
        "description": "Math",
            "length": "4 months"
    }, {
        "description": "English",
            "length": "6 months"
    }]
}];

Not sure if this is really an Angular question - You need a way to parse the raw json data in javascript.

One way to do it is to use a functional library like Underscore, which provides functional like utilities to perform these kind of operations.

See http://jsfiddle.net/9W5YF/2/ for an example, and check http://underscorejs.org for documentation on underscore.

var studentsDoingMaths = _.filter(json, function (student) {
var doingMaths = doingSubject("Math");
return subjectSearch(student, doingMaths);});