I'm using this pipes example inside my app, and it works fine for simple objects, but not for nested objects, for example lets take the example in the link and change the auther to an object instead of string, now the author will transform from this :
"author": "George R. R. Martin",
To this :
"author": {
"name": "George R. R. Martin",
"age": 25
}
I also changed the filter value to adapt the changes :
[(ngModel)]="filter.author.name"
However after these changes the searcher is not working any more for the author input.
Am I missing something here?
The reason is that the filter is defined as an instance of the Book class: filter: Book = new Book();
, which means that when you try to do this [(ngModel)]="filter.author.name"
you get an error because the Book
class defines author
as a string, not an object with a name
property.
A possible solution is to create an Author
class with the required properties (i.e. name and age) and the correspondent authorFilter
of type Author
. You can then modify the filter to look for the nested property age
when the filter is of type Author
.