Select default option value from typescript angular 6

前端 未结 14 1563
轻奢々
轻奢々 2020-12-09 07:30

I have a select html like this:


                        
    
提交评论

  • 2020-12-09 08:17

    Correct Way would be :

    <select id="select-type-basic" [(ngModel)]="status">
        <option *ngFor="let status_item of status_values">
        {{status_item}}
        </option>
    </select>
    

    Value Should be avoided inside option if the value is to be dynamic,since that will set the default value of the 'Select field'. Default Selection should be binded with [(ngModel)] and Options should be declared likewise.

    status : any = "47";
    status_values: any = ["45", "46", "47"];
    
    0 讨论(0)
  • 提交回复
    热议问题