问题描述
我在使用 Angular 6 时遇到两个错误 -
I am using Angular 6 where I am getting two errors -
./src/app/app/img/img.service.ts 中的错误找不到模块:错误:无法解析/Users/user/Projects/A4/imageSearch/src/app/app/img"中的rxjs/add/operator/map"
ERROR in ./src/app/app/img/img.service.tsModule not found: Error: Can't resolve 'rxjs/add/operator/map' in '/Users/user/Projects/A4/imageSearch/src/app/app/img'
src/app/app/img/img.service.ts(21,9) 中的错误:错误 TS2339:Observable"类型上不存在属性map".
ERROR in src/app/app/img/img.service.ts(21,9): error TS2339: Property 'map' does not exist on type 'Observable'.
推荐答案
我在使用 rxjs
map
操作符时遇到了类似的问题.目前我使用的是 Angular 6.要知道您使用的是哪个版本:
I faced similar problem with rxjs
map
operator. Currently I'm using Angular 6. To know which version you are using:
ng --version
或
ng -v
如果您还使用 angular 6,请查看 https://www.academind.com/learn/javascript/rxjs-6-what-changed/
If you are also using angular 6, then please checkout https://www.academind.com/learn/javascript/rxjs-6-what-changed/
- 需要您更改导入语句的不同内部结构
- pipe() 作为链接操作符的方法,链接它们的旧方法将不起作用
假设您将 map 用于 http.get
方法:
Let's say you use map for http.get
method:
import { map } from 'rxjs/operators';
private url = "some site...";
constructor(private http: HttpClient) { }
dailyForecast() {
return this.http.get(this.url).pipe(map(result => result));
}
不是: this.http.get(this.url).map(result => result);
这篇关于Angular 6:获取错误模块“rxjs/add/operator/map"的地方类型“Observable<Response>"上不存在另一个错误“map"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!