Typescript code:
import { Injectable } from \'@angular/core\';
import { Observable } from \'rxjs/Observable\';
import { of
Just remove /Observable
from 'rxjs/Observable';
If you then get Cannot find module 'rxjs-compat/Observable'
just put below line to thr terminal and press enter.
npm install --save rxjs-compat
I replaced the original code with import { Observable, of } from 'rxjs'
, and the problem is solved.
use return Observable.of(HEROES);
My resolution was adding the following import:
import { of } from 'rxjs/observable/of';
So the overall code of hero.service.ts after the change is:
import { Injectable } from '@angular/core';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
import { of } from 'rxjs/observable/of';
import {Observable} from 'rxjs/Observable';
@Injectable()
export class HeroService {
constructor() { }
getHeroes(): Observable<Hero[]> {
return of(HEROES);
}
}
Try this:
npm install rxjs-compat --save
What helped me is:
Get rid of all old import paths and replace them with new ones like this:
import { Observable , BehaviorSubject } from 'rxjs';)
Delete node_modules
folder
npm cache verify
npm install