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 에서 도움이 될 수 있습니다이 문서를 참조하십시오
- rxjs : 작성 방법, 유형, 스케줄러 및 유틸리티
import {Observable, Subject, asapScheduler, pipe, from, from, interval, merge, fromEvent} from 'rxjs';
- rxjs/operators: All pipeable operators:
import { map, filter, scan } from 'rxjs/operators';
- rxjs/webSocket: The web socket subject implementation
import { webSocket } from 'rxjs/webSocket';
- rxjs/ajax: The Rx ajax implementation
import { ajax } from 'rxjs/ajax';
- 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:
Get rid of all old import paths and replace them with new ones like this:
import { Observable , BehaviorSubject } from 'rxjs';)
Delete
node_modules
foldernpm cache verify
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
'IT' 카테고리의 다른 글
UIView 상단에 테두리를 추가하는 방법 (0) | 2020.06.26 |
---|---|
대화 상자 스타일 활동 창을 가져 와서 화면을 채우려면 어떻게해야합니까? (0) | 2020.06.26 |
WordPress 게시물 추천 이미지 URL을 얻는 방법 (0) | 2020.06.26 |
DistutilsOptionError : home 또는 prefix / exec-prefix를 제공해야합니다. (0) | 2020.06.26 |
AngularJs에서 날짜 필터를 기준으로 내림차순 (0) | 2020.06.26 |