How do I set default value on md-select component from angular 2 material design?

后端 未结 3 1396
慢半拍i
慢半拍i 2021-02-18 20:23

I have the following select component that gets populated from a data coming from a rest api. How Can I set default selected value on md-select?

  

        
3条回答
  •  余生分开走
    2021-02-18 20:48

    To set default value to md-select you need to set default value to the variable that you are using in [(ngModel)]. In your case:

    Component Html =>

    
      
                {{warehouse.description}}
     
    
    

    Component Script =>

    @Component({
      selector: 'select-form-example',
      templateUrl: './select-form-example.html',
    })
    
    constructor() {
      this.selectedProductWarehouse.warehouse = "default value"
    }
    

提交回复
热议问题