reservedcoders: ReservedCoders[];
export class ReservedCoders{
constructor(
public coderID:number
){ }
}
mycoder是一个数组
<td>
<div *ngIf="reservedcoders.find(s => s.coderID == mycoder.svUserID); else notEqual">
<button type="button" (click)="releasePopUp(mycoder.svUserID,mycoder.name)" class="btn btn-primary">Release</button>
<button type="button" (click)="addAdditionalPopUp(mycoder.svUserID,mycoder.name)" class="btn btn-primary">Add 10%</button>
</div>
<ng-template #notEqual>
<button type="button" (click)="releasePopUp(mycoder.svUserID,mycoder.name)" disabled class="btn btn-primary">Release</button>
<button type="button" (click)="addAdditionalPopUp(mycoder.svUserID,mycoder.name)" disabled class="btn btn-primary">Add 10%</button>
</ng-template>
</td>
答案 0 :(得分:0)
我不确定确切的问题是什么,但过去我发现* ngIf绑定中的某些复杂表达式确实会失败。
可能的最佳解决方案是修改代码以在组件中调用一个简单方法,并在该方法中实现“查找”。
例如,在您的组件中实现它:
public coderIdIsReserved(): boolean {
return this.reservedcoders.find(s => s.coderID === mycoder.svUserID) ;
}
并将您的模板更改为:
<div *ngIf="coderIdIsReserved(); else notEqual">