Hi,
I have a scenario, where I load and write a JSON file to a database. The content of that JSON contains the whole object as JSON. In my situation I want to have a DropDownList that reads a list of items T from the database. The previously loaded JSON contains a property of type T. This property is settable through the DropDownList. If I select a value from the DropDownList I want to store the complete object to the object and therefore as JSON to the database.
Database obj
{
...
"propOfTypeT": { "id": 1, "name": "name1" },
...
}
Data Source for DropDownlist:
[
{"id": 1, "name": "name1" },
{"id": 2, "name": "name2" }
{"id": 3, "name": "name3" }
]
if I select the second entry I want the resulting json to be:
{
...
"propOfTypeT": { "id": 2, "name": "name2" }
...
}
How do I achieve this. My current solution was to listen on (valueChange) and read from getDataFromValue. Is there some workaround or a solution on your side that solved this issue?
MaterialDesign solves it like this way:
<mat-select [(ngModel)]="item.propOfTypeT" [compareWith]="compareWithFunction">
<mat-option *ngFor="let item of items | async" [value]="item">
{{item.name}}
</mat-option>
</mat-select>
Possibly related to
Object as Value Field | Angular Forums | Syncfusion