【问题标题】:how to get a selected value from a dropdown list如何从下拉列表中获取选定的值
【发布时间】:2018-05-19 10:19:32
【问题描述】:

我正在开发 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);
  });
}

任何想法,提前谢谢你

【问题讨论】:

    标签: angular spring-boot select data-binding


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-03-07
      • 1970-01-01
      • 2019-01-28
      • 2021-02-21
      • 1970-01-01
      相关资源
      最近更新 更多