enter image description hereI am using the httpService to get data from an mock api, but it throws error
I am using a service
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class WishService {
constructor(private http: HttpClient) {
}
getWishes(){
return this.http.get('https://6697ee3602f3150fb66f83cb.mockapi.io/api/v1/wishItem')
}
}
and then I am injecting the service into my app component
constructor(events: EventService, private wishService: WishService) {
events.listen('removeWish', (id: any) => {
const index = this.items.findIndex((item) => item.id === id);
if (index !== -1) {
this.items.splice(index, 1);
}
});
}
ngOnInit(): void {
this.wishService.getWishes().subscribe((data: any) => {
this.items = data;
});
}
but I receive error in my browser
I might be missing something I guess, can someone help me out?
since I am on the latest version of Angular, for me httpsClientModule is depreceated and I do not have an app.module.ts file, I didn’t get much information to solve it and the docs were not that helpful because I didnt understand what it required me to do.
3
As mentioned before, you need to use provideHttpClient. Here’s a link to a blog which shows how to do it in the newer version of Angular Angular http in standalone components