I have following template
<select [(ngModel)] = "selectedLocation">
<option *ngFor="let location of allLocationNames" [ngValue]="location">{{location.name}}</option>
</select>
The component has following ngOnInit
export class TestComponent implements OnInit {
@Input() public guest: Guest;
public allLocationNames: Location[] = []
public selectedLocation: Location;
constructor(private apiService: ApiService) {
}
ngOnInit() {
this.allLocationNames = this.apiService.allLocationNames;
this.selectedLocation = this.guest.location;
}
}
I would like the default selected element to be the one set in this.selectedLocation
when the component loads. Right now the selected element in the drop down list seems to be a blank entry.
I am on Angular 5