I'm trying to pull JSON files from the web and I am doing something wrong. Here is my code:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class PullanaliticsService {
theUrl: string = 'https://jsonplaceholder.typicode.com/post';
res = [];
private httpClient: HttpClient;
constructor() { }
httpGetAsync()
{
var t = this.httpClient.get(this.theUrl).subscribe((res) => {
console.log(res);
});
return t
}
(I changed this.theUrl
to a page everyone can view)
I am getting the error:
DashboardComponent.html:4 ERROR TypeError: Cannot read property 'get' of undefined
at `PullanaliticsService.push../src/app/pullanalitics.service.ts.PullanaliticsService.httpGetAsync (pullanalitics.service.ts:22)`
which sounds like the URL is not working but I cannot figure out why.