I am trying to filter an array in a ngFor. If I do below I get an error:
html:
<div *ngFor="let group of filterGroups(report.assetGroups)">
error: Cannot read property 'assetGroups' of undefined.
If I do following I get another error:
html:
<div *ngFor="let group of filterGroups(report?.assetGroups)">
error:
TechnicalManagerReportComponent.html:66 ERROR TypeError: _co.filterGroups is not a function
So I am kind of stuck on how to do the filtering. This is my filter function:
filterGroups(itemList: AssetGroup[]): AssetGroup[] {
let result: AssetGroup[] = [];
return result;
}
Notice the ngFor works perfectly without the filter function.
My init method:
ngOnInit() {
this.route.params.subscribe( params => {
this.reportId = params.reportId;
this.apiService.getReportComplete(this.reportId).subscribe((data) => {
this.report = data;
this.loadGraph(this.report);
});
});
}
And service:
getReportComplete(reportId:string):Observable<ReportComplete>{
var url = `https://xxx.azurewebsites.net/api/reportcomplete/${reportId}`;
return this.httpClient.get<ReportComplete>(url).pipe(
map(x => new ReportComplete(x)));
}
filterGroupsdefined in the classTechnicalManagerReportComponent?let group of filterGroups(null)?reportvariable is assigned some async operation?