Изменить значение ячейки таблицы в соответствии с выбранным значением из выбора в той же строке в Angular - PullRequest
0 голосов
/ 06 апреля 2020

У меня есть таблица служб, где каждая строка содержит раскрывающийся список, а каждая запись представляет собой тип службы. Тип услуги содержит название и стоимость. Я хотел бы отображать соответствующую стоимость всякий раз, когда я выбираю тип услуги для каждой строки.

See image

<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>

1 Ответ

0 голосов
/ 06 апреля 2020

Я попробовал это решение, и оно сработало для меня:

<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>
...