I have a JSON array that I need to iterate through in order to display data using an NGfor Loop. My goal is to apply filters after the data has been loaded to refine the results. The issue I am facing is that my pipe filter is returning 'cannot read property of undefined'. What mistake am I making? To simplify, I have omitted the http Request to fetch data as well as the return logic on the pipe statement.
// component
import { Observable } from 'rxjs/Rx';
currentData:any = httpRequest; // Simplified
// html
<div *ngFor="let item of currentData | async | datePipe; let i = index">
//display content
</div>
// pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'datePipe'
})
export class DatePipe implements PipeTransform {
transform(time:any []): any[] {
console.log(time);
return time.filter(it => it["createDt"] != -1); // Simplified
}
}
*Updated fix *
// html
<div *ngIf="currentData?.length > 0">
<div *ngFor="let item of currentData | datePipe; let i = index">
//display content
</div>
</div>
//pipe
transform(time:any): any {
for(let key of time){
console.log(key.somevalue);
}
}