Started to learn angular services and DI but stuck trying to get json data from url in a service. This is the service.ts code:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { Employees } from '../models/emp';
@Injectable()
export class EmployeeService {
url = 'http://www.mocky.io/v2/5e712acd30000029007a34b8';
constructor(
private http: HttpClient
) { }
getEmployees(): Observable<Employees> {
// make http request to the given url and fetch the contacts
return this.http.get<Employees>(this.url);
}
}
Error in console:
HttpErrorResponse {headers: {…}, status: 0, statusText: "Unknown Error", url: "http://www.mocky.io/v2/5e712acd30000029007a34b8"…}
Link to stackblitz demo app:
url = 'https://www.mocky.io/v2/5e712acd30000029007a34b8';