0

My select control is as below

    <select formControlName="productType">
        <option *ngFor="let option of optionsArray; let i = index"
                [selected]="i===0">
            {{ option.name }}
        </option>
    </select>

In my ts file the optionsArray is a property

@Input( 'options'):IMyOption[]

get optionsArray(): IMyOption[] {
    return Object.values( this.options );
}

The options is a input from parent component. All I want is to the select the first item but is always blank. The options are populated from the parent correctly. How can I get [selected] to work? Please help.

user2837961
  • 1,505
  • 3
  • 27
  • 67

1 Answers1

0

Try like this.

<select formControlName="productType">
    <option *ngFor="let option of optionsArray; let i = index"
            [selected]="i===0 ? 'true': ''">
        {{ option.name }}
    </option>
</select>
José Polanco
  • 574
  • 4
  • 19