【发布时间】:2021-09-25 06:09:40
【问题描述】:
我的primeng 表在每一行都有按钮,只要我点击该按钮应该禁用的任何按钮。但是在我的代码中,单击一次按钮就会禁用所有按钮。请指导我如何仅禁用单击的按钮(我不希望按钮切换,禁用的按钮显示仅在页面刷新时启用)。到目前为止,我已经尝试过以下代码。
import { Component } from '@angular/core';
import {MenuItem} from 'primeng/api';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
didAction: boolean = false;
private action() {
this.didAction = true; //what to do here to disable only the clicked button in the row
}
}
<p-table [value]="cars">
<ng-template pTemplate="header">
<tr>
<th>Vin</th>
<th>Year</th>
<th>Brand</th>
<th>Action</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>{{car.vin}}</td>
<td>{{car.year}}</td>
<td>{{car.brand}}</td>
<td>
<p-button (click)="action()" class="pointer" label="Click" [disabled]="didAction()"></p-button>
</td>
</tr>
</ng-template>
</p-table>
【问题讨论】:
标签: html angular events primeng primeng-table