【问题标题】: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>
    

    【讨论】:

    • 检查 ngModel 变量
    猜你喜欢
    • 1970-01-01
    • 2020-06-25
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    • 2021-02-16
    • 2013-10-30
    • 2016-11-04
    • 2017-03-05
    相关资源
    最近更新 更多