Angular 4 setting selected option in Dropdown

前端 未结 6 1047
渐次进展
渐次进展 2020-12-13 17:34

several questions about this and diffrent answeres. But none of them realy answeres the question. So again:

Setting default of a Dropdown select by value isnt workin

6条回答
  •  遥遥无期
    2020-12-13 18:11

    If you want to select a value as default, in your form builder give it a value :

    this.myForm = this.FB.group({
        mySelect: [this.options[0].key, [/* Validators here */]]
    });
    

    Now in your HTML :

    What my code does is giving your select a value, that is equal to the first value of your options list. This is how you select an option as default in Angular, selected is useless.

提交回复
热议问题