My Ionic 6 + Angular 14 application is currently facing an issue with displaying data retrieved from an API...
I have implemented a service to fetch the data from the API and then called this service in the component. The app compiles without any errors and there are no console errors in the browser...
I am seeking assistance in identifying where I may have made a mistake?
Below is the code snippet for my service:
async getCategories() {
const token = await Preferences.get({ key: 'TOKEN_KEY' });
const headers = new HttpHeaders().set('Authorization', `Bearer ${token.value}`);
this.httpClient.get(`${environment.apiUrl}categories`, {headers}).subscribe(
data => {
this.categories = data;
},
error => {
console.log('Error', error);
}
);
}
And here is the relevant code from the component.ts file:
ngOnInit() {
this.getCategories();
}
getCategories() {
this.categories = this.categoriesService.getCategories();
}