IT

Angular- "내 보낸 멤버 'Observable'이 없습니다"

lottoking 2020. 6. 26. 07:50
반응형

Angular- "내 보낸 멤버 'Observable'이 없습니다"


암호

오류 정보

타입 스크립트 코드 :

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';

@Injectable({
  providedIn: 'root'
})
export class HeroService {

  constructor() { }

  getHeroes(): Observable<Hero[]> {
    return of(HEROES);
  }

}

오류 정보 :

오류 TS2307 : 'rxjs-compat / Observable'모듈을 찾을 수 없습니다. node_modules / rxjs / observable / of.d.ts (1,15) : 오류 TS2307 : 'rxjs-compat / observable / of'모듈을 찾을 수 없습니다. src / app / hero.service.ts (2,10) : 오류 TS2305 : 모듈 ' "F : / angular-tour-of-heroes / node_modules / rxjs / Observable"'에 내 보낸 멤버 'Observable'이 없습니다. src / app / hero.service.ts (15,12) : 오류 TS2304 : 'of'이름을 찾을 수 없습니다.

package.json Angular 버전의 파일 :

버전


자세한 내용 Angular 6 에서 도움이 될 수 있습니다이 문서를 참조하십시오

  1. rxjs : 작성 방법, 유형, 스케줄러 및 유틸리티
import {Observable, Subject, asapScheduler, pipe, from, from, interval, merge, fromEvent} from 'rxjs';
  1. rxjs/operators: All pipeable operators:
import { map, filter, scan } from 'rxjs/operators';
  1. rxjs/webSocket: The web socket subject implementation
import { webSocket } from 'rxjs/webSocket';
  1. rxjs/ajax: The Rx ajax implementation
import { ajax } from 'rxjs/ajax';
  1. rxjs/testing: The testing utilities
import { TestScheduler } from 'rxjs/testing';

Apparently (as you point in the error log), after updating to Angular 6.0.0 rxjs-compat is missing.

Run npm install rxjs-compat --save to install. Should fix it.


Just put:

import { Observable} from 'rxjs';

Just like that. Nothing more or less.


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

여기에 이미지 설명을 입력하십시오

여기에 이미지 설명을 입력하십시오


You are using RxJS 6. Just replace

import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';

by

import { Observable, of } from 'rxjs';

Try this:

npm install rxjs-compat --save

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

I had a similar issue. Back-revving RXJS from 6.x to the latest 5.x release fixed it for Angular 5.2.x.

Open package.json.

Change "rxjs": "^6.0.0", to "rxjs": "^5.5.10",

run npm update


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);
  }
}

The angular-split component is not supported in Angular 6, so to make it compatible with Angular 6 install following dependency in your application

To get this working until it's updated use:

"dependencies": {
"angular-split": "1.0.0-rc.3",
"rxjs": "^6.2.2",
    "rxjs-compat": "^6.2.2",
}

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

In my case this error was happening because I had an old version of ng cli in my computer.

The problem was solved after running:

ng update

ng update @angular/cli


업데이트 각도 - 메모리 - 웹 API 버전. angular-tour-of-heroes 튜토리얼 중에 설치된 기본 angular-in-memory-web-api 버전 은 0.4입니다. 내 경우에는 매력처럼 작동했습니다. (RxJS 6과 함께 Angular 7 사용)

npm i angular-in-memory-web-api@0.8.0

사용하다 return Observable.of(HEROES);

참고 URL : https://stackoverflow.com/questions/49840152/angular-has-no-exported-member-observable

반응형