When looking to "make" the selected item, it is commonly understood as setting it. Here is one way to achieve this, although there may be alternative methods.
To set the [attr.selected]
in the option tag:
<select class="form-control" name="Underwriter">
<option *ngFor="let underwriter of policyModel?.underwriterList" [ngValue]="underwriter.value" [attr.selected]="underwriter.text === underwriterTextString ? true : null">{{underwriter.text}}</option>
</select>
In your code, ensure that you assign a value to underwriterTextString
when the WebService API provides a response.
If underwriter.text
does not yield the desired results, consider using underwriter.value
.
However, if your objective now is to "get" the selected item, you can utilize the change event within the select
tag:
<select class="form-control" (change)="onChangeunderwriter($event)" name="Underwriter">
<option *ngFor="let underwriter of policyModel?.underwriterList" [ngValue]="underwriter.value" [attr.selected]="underwriter.text === underwriterTextString ? true : null">{{underwriter.text}}</option>
</select>
Your code should include something like this:
onChangeunderwriter(event) {
//the value will be set in event.target.value;
}