angular 2 - how to set <select> default selected option

前端 未结 2 505
陌清茗
陌清茗 2021-02-12 08:23

My template is like this


How can I set optio

2条回答
  •  太阳男子
    2021-02-12 09:03

    
    
    export class MyComponent {
      defaultValue = 'PM';
    }
    

    Usually it's done like

    
    
    export class MyComponent {
      values = ['AM', 'PM'];
      defaultValue = this.values[1];
    }
    

    Hint For non-string values use `[ngValue]="..."

    
    

提交回复
热议问题