Here is my solution:
An example of time zones. From the backend, I got the following object:
activeItem = { "timezone": { "timeZoneHolder": "Europe", "region": "Europe/Paris (CEST)", "UTC": "UTC+1" }}
And the same element from my model looks a little different, as the source changes:
{ "timeZoneHolder": "France", "region": "Europe/Paris", "UTC": "UTC +01:00" }
As you can see, a little different.
So here is my model:
timeZones = [{ "timeZoneHolder": "France", "region": "Europe/Paris", "UTC": "UTC +01:00" }, { "timeZoneHolder": "French Polynesia", "region": "Pacific/Gambier", "UTC": "UTC -09:00" }]
And here is the inscription for choice, it works like a charm:
<select id="timezone" name="timezone" [(ngModel)]="activeItem.timezone"> <option [ngValue]="activeItem.timezone" [selected]="true" disabled hidden>{{activeItem.timezone.region}}</option> <option *ngFor="let timeZone of timeZones" [ngValue]="{timeZoneHolder: timeZone.countryName, region: timeZone.timeZone, UTC: timeZone.UTC}"> {{timeZone.timeZone}} </option>
Enjoy :)
source share