Angular 4 - Select default value in dropdown [Reactive Forms]

前端 未结 7 1694
不知归路
不知归路 2020-12-01 00:52

In Angular 4, I have the following configuration defined in a json config file.

 countries: [\'USA\', \'UK\', \'Canada\'];
 default: \'UK\'

7条回答
  •  一个人的身影
    2020-12-01 01:39

    You have to create a new property (ex:selectedCountry) and should use it in [(ngModel)] and further in component file assign default value to it.

    In your_component_file.ts

    this.selectedCountry = default;
    

    In your_component_template.html

     
    

    Plunker link

提交回复
热议问题