【发布时间】:2019-03-05 08:09:15
【问题描述】:
我在 ngFor 组件中有一组按钮,我希望它们是互斥的。我想设计它,当我单击一行中的第一个按钮时,在我单击同一行中的相应按钮之前不能再次单击它。这是我的 Typescript sn-p 和我创建的函数;
showTime(staff){
staff.time = new Date();
}
displayTime(staff){
staff.times = new Date();
}
这是我的 HTML sn-p;
<tbody>
<tr *ngFor="let staff of staffs" class="m-1 p-1 bg-light">
<td>
{{staff.name}}
</td>
<td>
{{staff.department}}
</td>
<td>
<button [disabled]="!flagOne" (click)="showTime(staff)">Click</button>
<span *ngIf="staff.time">
Time: {{staff.time | date: 'shortTime'}}
</span>
</td>
<td>
<button [disabled]="!flagTwo" (click)="displayTime(staff)">Click</button>
<span *ngIf="staff.times">
Time: {{staff.times | date: 'shortTime'}}
</span>
</td>
</tr>
</tbody>
我的数组如下所示:
module.exports = function () {
return {
staff: [
{ id: 1, name: "xxx", department: "Development",
role: "Team Lead", time: null },
{ id: 2, name: "xxx", department: "Development",
role: "Back End", time: null },
{ id: 3, name: "xxx", department: "Security",
role: "Front End",time: null },
{ id: 4, name: "xxx", department: "Infrastructure",
role: "Corper", time: null },
{ id: 5, name: "xxx", department: "Infrastructure",
role: "xxx", time: null },
{ id: 6, name: "xxx", department: "Management",
role: "Assistant", time: null },
{ id: 7, name: "xxx", department: "Management",
role: "Director", time: null }
],
entries: []
}
【问题讨论】:
标签: html angular typescript