ngFor 过滤器在 child 组件中返回无项目消息
ngFor filter retuns no items message in child component
我有一个 parent 集合,其中包含 children 个组件。
[parent]
[child]
[child]
[parent]
[child]
我在 children 的 ngFor 上有一个过滤器,
当我过滤时,它会过滤数据,但我的视图最终看起来像这样:
[parent]
[parent]
[child]
如果 child 没有项目,是否可以过滤掉 parent?或者,让它做这样的事情:
[parent]
No Items Found!
[parent]
[child]
感谢大家的帮助,刚刚学习Angular 7.
html:
<div style="margin-top: 30px;">
<div *ngFor="let organization of column.boardColumnWorkItems">
<div class="row">
<div class="col-sm-4 organization-row">
{{organization.name}}
</div>
</div>
<app-board-column-tile *ngFor="let workItem of organization.workItems | workItemFilter:filterTerm"
[boardColumnWorkItem]="workItem">
</app-board-column-tile>
</div>
</div>
filter/pipe:
transform(workItems: any, filterTerm: any): any {
console.log("WorkItemFilterPipe: " + filterTerm);
//Check if filter term is undefined
if (filterTerm === undefined)
return workItems;
//Return the filtered list of workitems
this.filteredWorkItems = workItems.filter(function (workItem) {
return workItem.filterData.includes(filterTerm.toLowerCase());
})
console.log(this.filteredWorkItems.length);
return this.filteredWorkItems;
}
您可以尝试如下操作:
<ng-container *ngIf="organization.workItems | workItemFilter:filterTerm as filteredWorkItems">
<app-board-column-tile *ngFor="let workItem of filteredWorkItems"
[boardColumnWorkItem]="workItem">
</app-board-column-tile>
<h3 *ngIf="filteredWorkItems.length === 0">No filtered results!</h3>
</ng-container>
我有一个 parent 集合,其中包含 children 个组件。
[parent]
[child]
[child]
[parent]
[child]
我在 children 的 ngFor 上有一个过滤器,
当我过滤时,它会过滤数据,但我的视图最终看起来像这样:
[parent]
[parent]
[child]
如果 child 没有项目,是否可以过滤掉 parent?或者,让它做这样的事情:
[parent]
No Items Found!
[parent]
[child]
感谢大家的帮助,刚刚学习Angular 7.
html:
<div style="margin-top: 30px;">
<div *ngFor="let organization of column.boardColumnWorkItems">
<div class="row">
<div class="col-sm-4 organization-row">
{{organization.name}}
</div>
</div>
<app-board-column-tile *ngFor="let workItem of organization.workItems | workItemFilter:filterTerm"
[boardColumnWorkItem]="workItem">
</app-board-column-tile>
</div>
</div>
filter/pipe:
transform(workItems: any, filterTerm: any): any {
console.log("WorkItemFilterPipe: " + filterTerm);
//Check if filter term is undefined
if (filterTerm === undefined)
return workItems;
//Return the filtered list of workitems
this.filteredWorkItems = workItems.filter(function (workItem) {
return workItem.filterData.includes(filterTerm.toLowerCase());
})
console.log(this.filteredWorkItems.length);
return this.filteredWorkItems;
}
您可以尝试如下操作:
<ng-container *ngIf="organization.workItems | workItemFilter:filterTerm as filteredWorkItems">
<app-board-column-tile *ngFor="let workItem of filteredWorkItems"
[boardColumnWorkItem]="workItem">
</app-board-column-tile>
<h3 *ngIf="filteredWorkItems.length === 0">No filtered results!</h3>
</ng-container>