I've attempted to use this code for fetching data from an API.
Below is the content of my product.service.ts file:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { map, Observable } from 'rxjs';
import { Product } from '../common/product';
import 'rxjs/add/operator/map';
@Injectable({
providedIn: 'root'
})
export class ProductService {
public baseURL ='http://localhost:8080/getBooks'
constructor(private http:HttpClient) { }
users(){
return this.http.get(this.baseURL);
}
}
This is how my homecompoent.ts looks like:
export class HomeComponent {
public sort: string;
public books: any ;
constructor(private bookData:ProductService)
{
this.bookData.books().subscribe((data) => {
this.books = data;
});
}
Please help me figure out why I'm encountering this subscribe error.