【问题标题】:How can I update values of a dropdown list with angular?如何使用角度更新下拉列表的值?
【发布时间】:2021-11-10 16:30:56
【问题描述】:
我想将值更新到下拉列表中,但是当我单击表单时,值更改为 null。
知道添加工作正常。任何人都可以帮助我吗?
这是我的 html 代码:
<div class="form-group">
<label for="service">Service</label>
<select id="service" class="form-control" ngModel="{{editPersonne?.service}}" name="serviceId">
<option value="">Service</option>
<option value="service.id" *ngFor="let service of services" >{{service.designation}}</option>
</select>
</div>
【问题讨论】:
标签:
mysql
angular
spring-boot
frontend
dropdown
【解决方案1】:
你应该使用变量
<div class="form-group">
<label for="service">Service</label>
<select id="service" class="form-control" [(ngModel)]="{{editPersonne?.service}}" name="serviceId">
<option value="">Service</option>
<option [value]="service.id" *ngFor="let service of services" >{{service.designation}}</option>
</select>
</div>
或
<div class="form-group">
<label for="service">Service</label>
<select id="service" class="form-control" ngModel="{{editPersonne?.service}}" name="serviceId">
<option value="">Service</option>
<option value="{{service.id}}" *ngFor="let service of services" >{{service.designation}}</option>
</select>
</div>