Saroj Joshi
Saroj Joshi

Reputation: 29

How to Use NgFor inside select option

This is my typescript file and *ngFor is not working inside select option

I have tried this as pic below

<select type ="text" name="AccountNo" [(ngModel)]="val.AccountNo" class="form-control" > Select Account Number
                    <option>---Select---</option>
                    <option *ngFor="let sdata of savingData">
                        {{savingData.AccNum}}
                    </option>
                </select>

Upvotes: 2

Views: 3084

Answers (1)

Krunal Shah
Krunal Shah

Reputation: 864

Your HTML -

<select [(ngModel)]="val.AccountNo" class="form-control" > Select Account Number
    <option>---Select---</option>
    <option *ngFor="let sdata of savingData" [value]="sdata.AccountNo">
        {{sdata.AccNum}}
    </option>
</select>

TS File - You need to Declare Model -

val:any = {
    AccountNo : string = "";
};

You will get the value in model. Let me know if my answer help you in any kind.

Upvotes: 2

Related Questions