APIservice.ts
public fetchData(owner: any) {
return this.http.get(`${this.url}/${owner}`, this.httpOptions).pipe(
catchError(e => {
throw new Error(e);
})
);
}
public fetchDataById(id: number, byId:string, owner: any) {
return this.fetchData(owner).subscribe(data => {
Object.keys(data).map(function(key) {
return data[key].filter(x => x[byId] === id);
});
})
station.service.ts
getStationsByOrganizationID(id) {
return this.APIservice.fetchDataById(id, 'orgId', 'station');
}
managestation.component.ts
getStationsByOrgID(id) {
this.sta = this.stationService.getStationsByOrganizationID(id);
}
managestation.component.html
<ion-content class="body">
<ion-button expand="block" (click)="onAddStation()">Add Station
<ion-icon name='add' slot="end"></ion-icon>
</ion-button>
<ion-list>
<ion-item *ngFor="let s of sta">
<ion-label>{{ s.name }}</ion-label>
<ion-label>{{ s.orgId }}</ion-label>
<ion-icon name='create' slot="end" (click)="onEditStation(s.id)"></ion-icon>
<ion-icon name='trash' slot="end" (click)="onDeleteStation(s.id)"></ion-icon>
</ion-item>
</ion-list>
</ion-content>
Error
ERROR Error: "[object Object]" Angular 11 core.js:4002
How do I retrieve the values of fetchDataById in managestation.component.ts and set it to this.sta?