I have ecountered a problem while trying to set the selected value in dropdown to equal value taken from my model object. Some explanations:
sourceSchemesList is of type Scheme[]
element contains property named scheme of type Scheme
Scheme looks like below:
{
name: string
packetName: string
packetVersion:
{
minor: number
major: number
}
}
When opening a page, first I initialize the select options' list and after that, I set value for currentSource.operations, with valid data. When opening a view, the dropdowns appear with correct options, but there is no selected value.
<div class="row" *ngFor='let element of currentSource.operations'>
<div class="col-md-10">
<select class="form-control col-sm-12" [(ngModel)]="element.scheme">
<option *ngFor="let row of sourceSchemesList" [ngValue]="row" [label]="row.packetName + ' : ' + row.name"></option>
</select>
</div>
<div class="col-md-2">
<button type="button" class="btn mini-button border-0 p-1" (click)="deleteSourceOperation(element)">
<i class="fa fa-minus" aria-hidden="true"></i>
</button>
</div>
I have tried using [selected] attribute and setting the condition to
"element.scheme.name===row.name && element.scheme.packetName===row.packetName && <comparing versions by every property>"
but it did not help. What else could interfere? May the problem exist because of that my ngModel is an array' object?
Edit: The objects are different, so they do not equal by references. This is why I wanted to use [selected].