Binding select element to object in Angular

后端 未结 14 1747
走了就别回头了
走了就别回头了 2020-11-22 02:41

I\'d like to bind a select element to a list of objects -- which is easy enough:

@Component({
   selector: \'myApp\',
   template: `

My Application&

14条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 03:43

    Create another getter for selected item

    Selected Country: {{selectedCountry?.name}}

    In ts :

    get selectedCountry(){
      let countryId = this.countryForm.controls.country.value;
      let selected = this.countries.find(c=> c.id == countryId);
      return selected;
    }
    

提交回复
热议问题