angular - “主题”类型上不存在属性“地图”'
问题描述
我有两个项目 - 一个在 angular 5 上 - 一切正常,还有 angular 6 ..
我的代码:
public keyUp = new Subject<string>();
const observable = this.keyUp
.map(value => (event.target as HTMLInputElement).value)
.flatMap((search) => {
return Observable.of(search).delay(300);
})
.subscribe((data) => {
this.filter = data;
});
和错误:
Property 'map' does not exist on type 'Subject<string>',
Property 'of' does not exist on type 'Observable'
我的进口:
import { Observable, Subject } from 'rxjs';
我尝试了各种导入,但结果是一样的..
解决方案
由于这在 Angular 6 中不起作用,因此可以安全地假设您使用的 Rxjs 版本是 5.5 或更高版本。
在这种情况下应适用以下语法:
import { map, flatMap, delay, debounceTime, distinctUntilChanged } from 'rxjs/operators';
import { of, Observable, Subject } from 'rxjs';
...
public keyUp = new Subject < string > ();
const observable = this.keyUp
.pipe(
map(value => (event.target as HTMLInputElement).value),
debounceTime(500),
distinctUntilChanged(),
flatMap((search) => {
return of(search).pipe(delay(300));
})
)
.subscribe((data) => {
this.filter = data;
});
推荐阅读
- android - 在 Android 中以编程方式选择和取消选择 ChipGroup 中的所有芯片
- node.js - 如何使用复合查询 firebase admin (NodeJS)
- java - 应用程序在连接到服务器时不断崩溃
- docker - 'docker run' 使用挂载卷选项 '-v' 并带有单个目录作为参数(源和目标不使用冒号 (":") 分割)
- kotlin - 检查地图的值是否具有三元组中的所有键 - Kotlin
- javascript - Trying to extract items from a nested javascript object tree using recursion
- javascript - 将反应表单数据上传到 Firebase 时出现问题
- google-maps - 如何在颤动中为谷歌地图创建自定义图像标记,并在自定义小部件中创建它?
- python - 如何导入烧瓶重新上传的模块
- java - ?:在Java中:如何更合理地结合res和resString?