![](/img/trans.png)
[英]This condition will always return 'false' since the types 'number' and 'string' have no overlap ngIf
[英]Why ngIf's condition with enum value always returns false
我正在尝试在ngIf
条件中使用枚举值,但始终将其评估为false
。
<ng-container *ngIf='action'>
<td *ngIf="action==action.EDIT">
<button (click)="actionClick(action.EDIT,data.id)">EDIT</button>
</td>
<td *ngIf="">
<button (click)="actionClick(action.DELETE,data.id)">DELETE</button>
</td>
</ng-container>
@Input() public action: Action;
Action: typeof Action;
在您的组件中,创建一个属性并分配您的enum:
enumAction = Action
在您的模板中:
*ngIf='action === enumAction.EDIT'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.