I am trying to consume an API URL. I am calling the API with the below code.
import {HttpClient, HttpClientModule, HttpParams} from "@angular/common/http";
@Injectable()
export class PropertyPrefService {
constructor(private http: HttpClient,
private configurationService:Configuration) {}
public searchProjects(propFilter:string):any{
let temp:any;
const options = propFilter ?
{
params: new HttpParams().set('query', propFilter)
} : {};
return this.http.get<any>(this.configurationService.propertySystemApiUrl, options)
.subscribe((results:any) => {
console.log(results);
});
}
In the Angular code I am not getting any response and am getting an error:
Http failure response for (unknown url): 0 Unknown Error".
However, when I make a request if I open up developer tools on Chrome, I see that the response is received from the server.
The URL is the "https://..." URL and not "http://...".
this.configurationService.propertySystemApiUrl
is actually your url? Try doing a console log before the http-request. Where do you call the method? I think maybe you need to add a return statement inside subscribe.return results
(after console.log(results)); – Darrick