【发布时间】:2021-06-14 18:53:45
【问题描述】:
在我的项目中,我有一个表格,其中根据之前的选择插入了各种干预措施。在更多干预的情况下,如果我在第一次干预时选择一个值,则在第二次干预时它也会改变。如何使选择独立?
- summary.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<table class="table table-hover table-bordered table-striped" style="display: contents;">
<caption></caption>
<thead style="background:#ce5e59; color: white;">
<tr>
<th scope="colgroup">Interventions:</th>
<th scope="colgroup">Surface Type:</th>
<th scope="colgroup">Price:</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let element of intervention; index as j">
<tr>
<td>{{element.int.code}}</td>
<td>
<select multiple [(ngModel)]="surface_type">
<option selected disabled [value]="0">Select</option>
<option [value]="1" [attr.disabled]="element.priceVis === 0 ? 'disabled' : null">Visible Surface</option>
<option [value]="2" [attr.disabled]="element.pricePlast === 0 ? 'disabled' : null">Plastered Surface</option>
<option [value]="3" [attr.disabled]="element.priceBoth === 0 ? 'disabled' : null">Both Surface</option>
</select>
</td>
<td *ngIf="surface_type == 0"></td>
<td *ngIf="surface_type == 1">{{element.priceVis}}€/{{element.unit}}</td>
<td *ngIf="surface_type == 2">{{element.pricePlast}€/{{element.unit}}</td>
<td *ngIf="surface_type == 3">{{element.priceBoth}}€/{{elemento.unit}}</td>
</tr>
</ng-container>
</tbody>
</table>
- summary.ts
intervention: Intervention[] = []
surface_type: number: 0
【问题讨论】:
-
你能把 sn-p 设为minimal reproducible example 吗?例如添加您的元素
-
将所有
[value]="X"替换为value="X",一切都会为您工作
标签: javascript html angular typescript ngfor