Angular - “has no exported member 'Observable'”

后端 未结 14 1884
陌清茗
陌清茗 2020-12-12 11:16

Typescript code:

import { Injectable } from \'@angular/core\';
import { Observable } from \'rxjs/Observable\';
import { of         


        
相关标签:
14条回答
  • 2020-12-12 11:49

    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
    
    0 讨论(0)
  • 2020-12-12 11:52

    I replaced the original code with import { Observable, of } from 'rxjs', and the problem is solved.

    0 讨论(0)
  • 2020-12-12 11:54

    use return Observable.of(HEROES);

    0 讨论(0)
  • 2020-12-12 11:58

    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);
      }
    }
    
    0 讨论(0)
  • 2020-12-12 12:00

    Try this:

    npm install rxjs-compat --save
    
    0 讨论(0)
  • 2020-12-12 12:00

    What helped me is:

    1. Get rid of all old import paths and replace them with new ones like this:

      import { Observable , BehaviorSubject } from 'rxjs';)

    2. Delete node_modules folder

    3. npm cache verify
    4. npm install
    0 讨论(0)
提交回复
热议问题