My goal is to retrieve data from a service and display it in a component. Below is the code for my service:
Service.ts
export class PrjService {
tDate: Observable<filModel[]>;
prjData:Observable<filModel[]>;
entityUrl;
constructor(){
this.entityUrl = 'PrjDetail/GetByRep';
this.tDate = service.get<ShipDateFilterModel[]>(this.entityUrl);
}
Below is the component where I attempt to fetch and process the data:
export class RFComponent implements OnInit {
cachedResults: any[];
shipToData: any;
constructor(private psService: PrjService)
{}
ngOnInit() {
this.psService.tDate.subscribe(x => this.cachedResults = x);
this.filterData = [...new Set(this.cachedResults.map(item => item.cus_name))].filter(Boolean);
}
However, when the service call is made, this.cachedResults
is undefined and I encounter an error when trying to filter:
ERROR TypeError: Cannot read property 'map' of undefined
I am unsure of what I might be missing here.