AngularJS ng-repeat filter for child node

I have the following JSON data structure

{ "firstName" : "John",
  "role" : "Manager",
  "status" : {
                "Id" : 30,
                "Status" : "Appointment booked",
                "statusDate" : 1467826508775
             },
  "surname" : "Smith",
  "title" : "Mr",
}

and I'm trying to use ng-repeat with a filter to the second level node status.Status. I tried the following, but the filter does not work.

ng-repeat="data in data | filter: {status.Status: 'Appointment booked'}"

Is this possible on ng-repeat or do I need to look at an alternative solution?

+4
source share
1 answer

You can always use a custom filter if all else fails:

ng-repeat="d in data | myFormat"

JS:

app.controller('myCtrl', function ($scope) {
    $scope.data = {
        "firstName": "John",
        "role": "Manager",
        "status": {
            "Id": 30,
            "Status": "Appointment booked",
            "statusDate": 1467826508775
        },
        "surname": "Smith",
        "title": "Mr",
    }
});

app.filter('myFormat', function () {
    return function (x) {
        if (x.status.Status == 'Appointment booked') {
            return x;
        }
    };
});

As mentioned in the comments

ng-repeat="d in data | filter : {status: { Status : 'Apointment booked'}}"

also works

+2
source

All Articles