【发布时间】:2025-12-29 07:50:09
【问题描述】:
在 *ngFor 迭代中,如果值等于特定值,则不要使用 Angular4 列出列表中的值。
我的模板:
<div class="desktop-list btn-group-vertical show-cat">
<button class="list-group-item list-group-item-action cat-btn" *ngFor='let category of categories' (click)="getCatName($event)">{{category}}<i class="glyphicon glyphicon-chevron-right"></i></button>
</div>
<div class="mobile-select show-cat">
<select class="mobile-select show-cat" [ngModel]="selectedCat" (ngModelChange)="change($event)" name="category" id="cat-column" placeholder="Select a Category">
<option [ngValue]="category" class="cat-btn" *ngFor='let category of categories'>{{category}}</option>
</select>
</div>
组件getCategories函数:
getCatgegories(masterProduct: number) {
this.service.getCatgegories(masterProduct)
.subscribe(response => {
this.categories = response.catList;
this.categories.splice(0,0, 'Select a Category');
this.masterName = response.name;
});
}
我想检查类别是否 = '选择一个类别',如果它返回 true,它将不会在按钮列表中显示该项目。我觉得这应该是一件容易完成的事情,但没有找到解决方案。 任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: angular angular-forms