javascript - Angular:是否可以在您的子项中重用 ngIf 中的方法的结果?
问题描述
我有一个问题,是否可以将模板中方法调用的结果放在元素上?controlError(item.name) 方法如果有错误返回一个带有错误的字符串 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>
如果有可能如何解决他?
解决方案
尝试指令的as
构造。*ngIf
<mat-error *ngIf="(controlError(item.name)) as result">
{{ result }}
</mat-error>
推荐阅读
- android - Android Paging 3 库:如何使用新参数更改列表?
- java - Discord Java Bot 没有响应
- android - 如何用 Flow 替换 LiveData
- php - 致命错误:未捕获的类型错误:filter_var():参数 #3 ($options) 必须是数组类型
- c - 将 C 数组中的一个字符转换为大写会给出 C4244 警告
- unity3d - 检查子弹来自玩家的有效方法 [Unity Multiplayer Mirror]
- python - 在条件下用最常见的数字替换缺失值
- javascript - HTML 视频播放器 - 如果选项卡失去焦点,则无法跳过视频并重新启动
- windows - 有没有办法改变 PrtScr 键执行的操作?
- javascript - 如何为表单中的不同选项组合生成不同的表格 [HTML/JS]