angular - 使用 *ngFor 迭代时检查值是否存在 - Angular 10
问题描述
我通过迭代两个数组来填充mat-select :
<mat-select>
<mat-optgroup *ngFor="let group of groups; trackBy: trackGroup" [label]="group.name">
<ng-container *ngFor="let question of group.questions; trackBy: trackQuestion">
<mat-option [value]="question._id">
{{question.title}}
</mat-option>
</ng-container>
</mat-optgroup>
</mat-select>
我想检查给定的问题 id 是否在列表中,而无需在控制器 ts 文件中重新进行迭代。如果它不存在,我想将一个类应用于垫选择之外的 div。像这样的东西:
<div [ngClass]="{'warning': !exists}">
<mat-select>
...
</mat-select>
</div>
我怎样才能做到这一点?我以为我可以在 trackBy 函数中做到这一点,但似乎组件变量尚未定义。
解决方案
推荐阅读
- angular - 在运行时将样式应用于 Angular 中的 NgBootstrap 模态
- java - 带有 Pageable 和 Page 的 Spring Data Repository 的自定义方法
- python - Python 模块在单独运行时运行,但在作为包装器的一部分导入时不运行
- android - Android App Bundles - 是否可以在一个版本中上传多个应用程序包?
- php - 从整个数据库中删除 product_id 的数据
- php - 如何解析离子网格中的 php 值
- c# - 如何在我输入退出或取消的每一刻中断表单流?
- html - 如何定位容器
- javascript - Java 将 byte[] 转换为 BigInteger
- autodesk-forge - 模型 URN 安全问题