Angular: ngIf 方法的结果是否有可能在你的子项中重用?

Angular: is it possible in the result of method in ngIf reuse in yours child item?

我有一个问题,是否可以将模板中方法调用的结果放入元素中? controlError(item.name) 方法 return 如果有错误 一个带有错误的字符串 else return null

<table class="w-100">
  <td *ngFor="let item of form.fields">
    <mat-form-field class="w-100" *ngIf="item.dataType==='string'">
        <mat-label>{{ item.labelDefault | translate}}</mat-label>
        <input type="text" matInput required formControlName="{{item.name}}">
        <mat-error *ngIf="controlError(item.name)">
          //result of controlError
        </mat-error>
    </mat-form-field>
  </td>
</table>

如果可以怎么解决他?

尝试 *ngIf 指令的 as 结构。

<mat-error *ngIf="(controlError(item.name)) as result">
  {{ result }}
</mat-error>