【发布时间】:2021-05-18 17:43:17
【问题描述】:
在我的项目中,我正在使用 angular 最新版本,我获取了一个 API 并得到了一些响应,因此我使用了 *ngFor 并在模板(HTML)mat-dropdown 中显示了 angular 材料中的数据。现在我的问题是基于 API 响应如何在文本之前显示图标?
在我的 API 响应中,我有操作系统类型,基于操作系统,我必须显示该图标。
*ngFor条件:
<mat-option
*ngFor="let item of activeItems">
<i *ngIf="hasIcon" class="fa-{{iconType}}"></i>
<span [textContent]="item.name"></span>
</mat-option>
图标条件:
public items: Page<PageObject>;
public iconType;
getItems() {
if(this.hasIcon == true ){
if(this.items.content.filter((item: PageObject) => item['andriod'])) {
this.iconType = 'andriod';
} else if(this.items.content.filter((item: PageObject) => item['ios'])) {
this.iconType = 'ios';
}
}
}
我尝试过这种方式,但它为所有项目应用了相同的图标。如果有人告诉我如何解决这个问题?
【问题讨论】:
标签: typescript angular8