Angular Material md-select default selected value

前端 未结 3 915
北荒
北荒 2021-01-07 17:36

I am using Angular 2 with Angular Material. Looking at the documentation, I am trying to get the select to have a default value as oppose to an empty place holder.

3条回答
  •  梦谈多话
    2021-01-07 18:33

    Use [(ngModel)]:

    
      One
      Two
    
    

    Component:

    selectedOption = '1';

    DEMO


    Edit #1:

    Since Material2.0.0#beta10 (specifically this PR) you can select a value using the value property of MatSelect:

    
      One
      Two
    
    

    Component:

    selectedOption = '1';

    Note that you can also use it with two-way data binding -> [(value)].

    DEMO

提交回复
热议问题