I am trying to use Angular Dropdown. The JSON is as follows-
{
{
"bookId":"1",
"authors":{ "author1", "author2"}
}
{
"bookId":"2",
"authors":{ "author2", "author3"}
}
}
Have created a class named Book which stores the above values in Book Array named books.
In html code have the following -
<select [(ngModel)]="book.id" (ngModelChange)='onBookSelected($event)'>
<option *ngFor="let book of books"
[value] = "book.authors">{{book.id}}</option>
</select>
In the component have the onBookSelected as follows-
onBookSelected(val: any)
{
console.log(val);
}
I dont get the list of authors but get
[object Object],[object Object],[object Object]
I also tried creating an array of class author and using it as follows-
onBookSelected(authorList : any)
{
console.log(authorList );
}
But get same output as
[object Object],[object Object],[object Object]
Could someone please help to get list of authors when the book is selected from the dropdown. Thanks