Currently diving into the world of Angular services and dependency injection, but encountering a roadblock while attempting to retrieve JSON data from a URL in a service. Here's a snippet of 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 message displayed in the console:
HttpErrorResponse {headers: {…}, status: 0, statusText: "Unknown Error", url: ""…}
Here is the link to access the StackBlitz demo app: