如何从下拉列表中获取选定的值

时间:2018-05-19 10:19:32

标签: angular spring-boot select data-binding

我正在使用spring boot中的后端应用程序和angular 5中的前端。 我有一个下拉列表。 这是列表中的代码。

<select #selectElem (change)="onSelectCat($event.target.value)" >

<option *ngFor="let categorie of categories" [value]="fournisseur.categorieid" id="categorieid" name="categorieid">
{{categorie.libelle}}
</option>
</select>

我希望从列表中检索所选的值,并通过单击按钮添加谁调用此函数将其与表单发送的提供程序对象一起添加:add.component.ts

newUser(fournisseur){
  this.fournService.createFourn(this.fournisseur).subscribe((fournisseur)=>{
    console.log(fournisseur);
   // this.router.navigate(['/*/listsuppliers'])
  },(error)=>{
    console.log(error);
  });
}

任何想法,提前谢谢

1 个答案:

答案 0 :(得分:0)

[(ngModel)] = "fournisseur.categorieid"申请select元素,并将[value]="fournisseur.categorieid"更改为[value]="categorie?.categorieid"中的option。这里https://angular.io/guide/forms#two-way-data-binding-with-ngmodel示例如何在select元素

中使用ngModel
相关问题