【发布时间】:2023-01-23 18:17:05
【问题描述】:
我需要当我点击表格的行时添加金额,当我再次点击同一行时我减去我添加的金额。我设法添加了它,但我不知道如何让它在再次单击时减去数量。
我已经设法使选定的行根据我是否选择它而改变颜色,但现在我需要在我再次单击该行时减去已添加的内容(如果我成功的话)。
这是我的 HTML:
<tbody>
<tr *ngFor="let item of articulos; index as i" (click)="total(item.cantidad)"
(click)="cambiarFlag(item)"
[ngClass]="{'seleccionada': item.selected, 'noSeleccionada': !item.selected}">
<td>{{item.articulo}}</td>
<td>{{item.cantidad}}</td>
<td>{{item.recogida}}</td>
</tr>
<br>
</tbody>
<div type="button" class="col border border-white border-4" id="other" type="button"
routerLink="/entry-order-lines-quantity" style="background-color:rgb(3, 71, 150);">
Cantidad {{totalCantidad}}
</div>
这是我的 ts:
export class EntryOrderLinesComponent implements OnInit {
totalCantidad: number = 0;
articulos = [
{
articulo: '385/65X22.5 HANKOOK AH51 160K (3003836)',
cantidad: 94,
recogida: '0',
selected: false,
},
{
articulo: '385/65X22.5 HANKOOK TH31 164K (3003309)',
cantidad: 60,
recogida: '0',
selected: false,
},
];
total(cantidad: number) {
this.totalCantidad += cantidad;
}
cambiarFlag(item: any) {
item.selected = !item.selected;
}
非常感谢你。
【问题讨论】:
标签: html angular typescript