[英]Change table cell value according to selected value from a select within the same row in Angular
我有一個服務表,其中每一行都包含一個下拉菜單,每個條目都是一個服務類型。 服務類型包含標題和成本。 每當我 select 為每一行服務類型時,我想顯示相應的成本。
<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>
我嘗試了這個解決方案,它對我有用:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.