It is supposed to call the pixabay API to search for images. Everything else seems fine however when I search for anything I get no results of images. I think it is because of the mapping line but not sure, I am a beginner with Angular
import {Injectable} from '@angular/core';
import { environment } from '../../environments/environment';
import { Http, Headers } from '@angular/http';
import { map } from 'rxjs/operators'
@Injectable()
export class ImageService{
private query: string;
private API_KEY: string = environment.PIXABAY_API_KEY;
private API_URL: string = environment.PIXABAY_API_URL;
private URL: string = this.API_URL + this.API_KEY + '&q=';
private perPage: string = "&per_page=10";
constructor(private _http: Http) { }
getImage(query){
return this._http.get(this.URL + query + this.perPage).map(res =>
res.json());
}
}
This is a snippet of my image-list.component.ts :
handleSuccess(data){
this.imagesFound = true;
this.images = data.hits;
console.log(data.hits);
}
handleError(error){
console.log(error);
}
constructor(private _imageService : ImageService) { }
searchImages (query: string){
return this._imageService.getImage(query).subscribe(
data => this.handleSuccess(data),
error => this.handleError(error),
() => this.searching = false
);
}
ngOnInit() {}