问题描述
我正在尝试关注有关角度的教程,但是该教程是在9月份完成的.我相信该人使用angular-cli 1.3.2.我不确定他使用的是哪个版本的rxjs.我使用的是角度cli 6.0.0和角度6以及rxjs 6.1.0.
Hi I'm trying to follow a tutorial on angular but the tutorial was made in September. I believe the person used angular-cli 1.3.2. I'm not sure which version of rxjs he was using. I'm using angular cli 6.0.0 and angular 6 with rxjs 6.1.0.
我遇到了一个问题,即找不到可观察到的.map.ERROR in xxx/xxx/dataService.ts(19,14): error TS2339: Property 'map' does not exist on type 'Observable<Object>'.
我查看了Observable类,但没有看到一个名为map的函数.
I am running into a problem where calling .map on observable is not found.ERROR in xxx/xxx/dataService.ts(19,14): error TS2339: Property 'map' does not exist on type 'Observable<Object>'.
I looked into the Observable class and I don't see a function called map.
angular 6或rxjs中是否有新方法来实现本教程要尝试的工作?
Is there a new way in angular 6 or rxjs to achieve what the tutorial is trying to do?
这是我的.ts文件:
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { map } from 'rxjs/operators';
@Injectable()
export class DataService {
constructor(private http: HttpClient) {
}
public products = [
];
loadProducts() {
return this.http.get("/api/products")
.map((data: any[]) => {
this.products = data;
return true;
});
}
}
这是ng --version
λ ng --version
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 6.0.0
Node: 8.11.1
OS: win32 x64
Angular: 6.0.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.0
@angular-devkit/build-angular 0.6.0
@angular-devkit/build-optimizer 0.6.0
@angular-devkit/core 0.6.0
@angular-devkit/schematics 0.6.0 (cli-only)
@ngtools/webpack 6.0.0
@schematics/angular 0.6.0 (cli-only)
@schematics/update 0.6.0 (cli-only)
rxjs 6.1.0
typescript 2.7.2
webpack 4.6.0
我做了一些挖掘工作,在我的node_modules/rxjs/observable文件夹中没有地图.*文件
I did a little digging and in my node_modules/rxjs/observable folder there is no map.* file
λ ls -R rxjs\observable
'rxjs\observable':
ArrayLikeObservable.d.ts IfObservable.d.ts combineLatest.d.ts if.js.map
ArrayLikeObservable.js IfObservable.js combineLatest.js interval.d.ts
ArrayLikeObservable.js.map IfObservable.js.map combineLatest.js.map interval.js
ArrayObservable.d.ts IntervalObservable.d.ts concat.d.ts interval.js.map
ArrayObservable.js IntervalObservable.js concat.js merge.d.ts
ArrayObservable.js.map IntervalObservable.js.map concat.js.map merge.js
BoundCallbackObservable.d.ts IteratorObservable.d.ts defer.d.ts merge.js.map
BoundCallbackObservable.js IteratorObservable.js defer.js never.d.ts
BoundCallbackObservable.js.map IteratorObservable.js.map defer.js.map never.js
BoundNodeCallbackObservable.d.ts NeverObservable.d.ts dom/ never.js.map
BoundNodeCallbackObservable.js NeverObservable.js empty.d.ts of.d.ts
BoundNodeCallbackObservable.js.map NeverObservable.js.map empty.js of.js
ConnectableObservable.d.ts PairsObservable.d.ts empty.js.map of.js.map
ConnectableObservable.js PairsObservable.js forkJoin.d.ts onErrorResumeNext.d.ts
ConnectableObservable.js.map PairsObservable.js.map forkJoin.js onErrorResumeNext.js
DeferObservable.d.ts PromiseObservable.d.ts forkJoin.js.map onErrorResumeNext.js.map DeferObservable.js PromiseObservable.js from.d.ts pairs.d.ts
DeferObservable.js.map PromiseObservable.js.map from.js pairs.js
EmptyObservable.d.ts RangeObservable.d.ts from.js.map pairs.js.map
EmptyObservable.js RangeObservable.js fromArray.d.ts race.d.ts
EmptyObservable.js.map RangeObservable.js.map fromArray.js race.js
ErrorObservable.d.ts ScalarObservable.d.ts fromArray.js.map race.js.map
ErrorObservable.js ScalarObservable.js fromEvent.d.ts range.d.ts
ErrorObservable.js.map ScalarObservable.js.map fromEvent.js range.js
ForkJoinObservable.d.ts SubscribeOnObservable.d.ts fromEvent.js.map range.js.map
ForkJoinObservable.js SubscribeOnObservable.js fromEventPattern.d.ts throw.d.ts
ForkJoinObservable.js.map SubscribeOnObservable.js.map fromEventPattern.js throw.js
FromEventObservable.d.ts TimerObservable.d.ts fromEventPattern.js.map throw.js.map
FromEventObservable.js TimerObservable.js fromIterable.d.ts timer.d.ts
FromEventObservable.js.map TimerObservable.js.map fromIterable.js timer.js
FromEventPatternObservable.d.ts UsingObservable.d.ts fromIterable.js.map timer.js.map
FromEventPatternObservable.js UsingObservable.js fromPromise.d.ts using.d.ts
FromEventPatternObservable.js.map UsingObservable.js.map fromPromise.js using.js
FromObservable.d.ts bindCallback.d.ts fromPromise.js.map using.js.map
FromObservable.js bindCallback.js generate.d.ts zip.d.ts
FromObservable.js.map bindCallback.js.map generate.js zip.js
GenerateObservable.d.ts bindNodeCallback.d.ts generate.js.map zip.js.map
GenerateObservable.js bindNodeCallback.js if.d.ts
GenerateObservable.js.map bindNodeCallback.js.map if.js
'rxjs\observable/dom':
AjaxObservable.d.ts AjaxObservable.js.map WebSocketSubject.js ajax.d.ts ajax.js.map webSocket.js
AjaxObservable.js WebSocketSubject.d.ts WebSocketSubject.js.map ajax.js webSocket.d.ts webSocket.js.map
推荐答案
在 rxjs@6
中,您可以将from作为独立函数使用:
In rxjs@6
you can use from as standalone function:
import { from } from 'rxjs';
另请参阅迁移到rxjs6指南
See also migration to rxjs6 guide
https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#import-paths
更新
您需要切换到管道语法,请确保从rxjs/operators中导入所有使用的运算符.例如:
You need to switch to pipe syntax, make sure you import all operators used from rxjs/operators. For example:
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
DOCUMENTATION
这篇关于Map在Observable< Object>上不存在与角度6.0.0和rxjs 6.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!