Ramakanth Reddy
Ramakanth Reddy

Reputation: 139

I am unable to sort with orderBy pipe for nested objects?

I have a array of objects. I want to sort some keys using orderBy pipe but due to the fact that i there are objects in the main object. I am unable to use the pipe.

example object

    var object = {
    Name :'John',
    City : 'Dallas',
    Address:{
    Street: 'xyz',
    Postal_code:123,
    }
}

so I have 1000 such objects in array,when i Use the orderBy pipe I am able to sort the keys but i am unable to sort the keys inside address object.

*ngFor = "object of objects | orderBy:'object.Address.Street':false"

This dint work. Can you guys please suggest some solutions.

Thank you

Upvotes: 1

Views: 804

Answers (1)

ashfaq.p
ashfaq.p

Reputation: 5469

There is no build-in orderBy pipe available in angular.

These are the only built-in pipes available for usage in templates.

build-in pipes Angular

You will have to create a custom pipe for this. Read more about creating pipes here: Custom pipes in angular

In your approach, you will have to use:

*ngFor = "object of objects | orderBy:'object.Address.Street':false"

Upvotes: 1

Related Questions