I have a model "currentProject" that contains some text-properties and has 1 property of another complex model , exposed by "energiePeil".
The second model is not that complex and looks like this :
export class EnergiePeil {
niveau: string;
epeil: number;
}
I have the necessary Read-functionality to retrieve the entire parent-model and all its properties (including the child-model) and I have an EnergiePeil[] member "energiePeillen" to list all possible values of the second model. When displaying the parent-model , I display some values of the parent-model but I also want to display the value of the submodel. Showing the entire list of EnergiePeil works correctly, however when opening the form the option does not select the correct value!
<div class="form-group">
<div class="col-md-4">
<select class="form-control" id="energiePeil"
required
[(ngModel)]="currentProject.energiePeil" name="energiePeil"
#energiePeil="ngModel">
<option *ngFor="let epeilVar of energiePeillen" [ngValue]="epeilVar" [value]="epeilVar.niveau">{{epeilVar.niveau}}</option>
</select>
<div [hidden]="energiePeil.valid || energiePeil.pristine" class="alert alert-danger">
Energiepeil is required
</div>
</div>
</div>
What am I doing wrong here? I have tried to use [selected] but this would not work neither..
<option *ngFor="let epeilVar of energiePeillen" [ngValue]="epeilVar" [selected]="epeilVar.niveau === currentProject.energiePeil.niveau">{{epeilVar.niveau}}</option>