【问题标题】:Change table cell value according to selected value from a select within the same row in Angular根据Angular中同一行内的选择中的选定值更改表格单元格值
【发布时间】:2020-07-17 20:36:34
【问题描述】:

我有一个服务表,其中每一行都包含一个下拉菜单,每个条目都是一个服务类型。服务类型包含标题和成本。当我为每一行选择一种服务类型时,我想显示相应的成本。

<table class="table table-striped table-responsive table-hover">
  <tr>
    <th>Service name</th>
    <th>Service type</th>
    <th>Price</th>
    <th></th>
  </tr>
  <tr *ngFor="let service of content.services">
    <td>{{service.title.fr}}</td>
    <td>
      <select name="servicetype" class="form-control" [(ngModel)]="selectedServiceType" (change)="showPrice($event)">
        <option value=""></option>
        <option *ngFor="let type of service.servicetypes" [ngValue]="type">
          {{type.title.fr}}
        </option>
      </select>
    </td>
    <td></td>
    <td><input name="service" type="radio" (change)="selectThisService(service)"></td>
  </tr>
</table>

【问题讨论】:

    标签: angular html-table html-select ngfor


    【解决方案1】:

    我尝试了这个解决方案,它对我有用:

    <table class="table table-striped table-responsive table-hover">
          <tr>
            <th>Service name</th>
            <th>Service type</th>
            <th>Price</th>
            <th></th>
          </tr>
          <tr *ngFor="let service of content.services; let i = index">
            <td>{{service.title.fr}}</td>
            <td>
              <select name="servicetype" class="form-control"[(ngModel)]="selectedServiceType[i]">
                <option value=""></option>
                <option *ngFor="let type of service.servicetypes" [ngValue]="type">
                  {{type.title.fr}}
                </option>
              </select>
            </td>
            <td>
              <div *ngIf="selectedServiceType[i]">
                {{selectedServiceType[i].cost}}
              </div>
            </td>
            <td><input name="service" type="radio" (change)="selectThisService(service)"></td>
          </tr>
        </table>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 2018-06-22
      相关资源
      最近更新 更多