Angular 无法在*ngFor ANGLAR2中声明变量

Angular 无法在*ngFor ANGLAR2中声明变量,angular,typescript,let,ngfor,Angular,Typescript,Let,Ngfor,我试图在*ngFor中声明一个我自己的变量,但它抛出错误并且不起作用 我循环浏览一组按钮,并在满足*ngIf内的条件时显示图标 <button *ngFor="let button of buttons;" type="button"> <i *ngIf="button.icon || (button.conditional && button.iconConditional)" [attr.class]="button.icon"></i&

我试图在
*ngFor
中声明一个我自己的变量,但它抛出错误并且不起作用

我循环浏览一组
按钮
,并在满足
*ngIf
内的条件时显示图标

<button *ngFor="let button of buttons;" type="button">
    <i *ngIf="button.icon || (button.conditional && button.iconConditional)" [attr.class]="button.icon"></i>
</button>
有人能帮忙吗

即使尝试在ngFor中添加showIcon变量,也会引发如下错误:

你的错误是什么?似乎是不可能的,但应该有办法:(我是唯一一个对此感到惊讶的新用户吗?我们究竟应该如何在循环中做任何有条件的事情?
<button *ngFor="let button of buttons; let showIcon = button.icon || (button.conditional && button.iconConditional)" type="button" [ngClass]="{'icon':showIcon}">
    <i *ngIf="showIcon" [attr.class]="button.icon"></i>
</button>