I'm trying to get data from a URL that gives JSON output to an Angular project.
When I follow http://localhost:3000/booking
on the browser it gives following output
[{"_id":"5cf35bbebaa52f4ab2f27b81","firstname":"lahiru","lastname":"madushan","email":"lahiru@lahiru.com","contact":770095174,"comments":"Done","xl":2,"md":1,"sm":3,"store":null,"pickup":null,"store_id":"df4xrttfvy","__v":0},
{"_id":"5cf3762e7410e55137b65c4e","firstname":"lahiru","lastname":"madushan","email":"lahiru@lahiru.com","contact":770095174,"comments":"Done","xl":2,"md":1,"sm":10,"store":null,"pickup":null,"store_id":"df4xrttfvy","__v":0}
]
But When I try to get this using angular service and store it in local storage. But When I check the LocalStorage data is not there.
This is the service.ts file
getBookings(): Observable<Booking[]>{
return this.http.get<Booking[]>('http://localhost:3000/booking/');
}
and component.ts file
ngOnInit() {
this.bookingService.getBookings()
.subscribe(data => this.bookings = data);
localStorage.setItem('bookings', JSON.stringify(this.bookings));
}
This does not give any errors in the console.
Please Tell me What have I done wrong hear.