Error on Angular5 Importing RxJS in the project

Issue

Observable not found, what do I? I do not know how to use rxjs on http. anyone can tell me Please?

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { IEmployee } from './employee';
import { Observable } from 'rxjs/Observable ';

@Injectable()
export class EmployeeService {

  private _url: string = "/assests/data/employee.json";
  constructor(private http: HttpClient) { }

  getEmployees(): Observable<IEmployee[]>{ 
    return this.http.get<IEmployee[]>(this._url);
  }
}

Solution

In case of rxjs 6, you need to import Observable like this:

import { Observable } from 'rxjs';

You can check it here:
https://github.com/ReactiveX/rxjs#installation-and-usage

Answered By – alexanto

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.