【发布时间】:2018-06-20 18:58:38
【问题描述】:
在我的 Angular 组件上,我使用了来自 RxJs 的两种方法,debounceTime() 和 distinctUntilChanged()
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
@Component({
selector: 'app-form4th',
templateUrl: './form4th.component.html',
})
export class Form4thComponent implements OnInit {
searchField: FormControl;
searches: string[] = [];
constructor() { }
ngOnInit() {
this.searchField = new FormControl();
this.searchField
.valueChanges
.debounceTime(400)
.distinctUntilChanged()
.subscribe(term => {
this.searches.push(term);
});
}
}
应用程序运行良好,没有错误甚至没有警告消息(构建)时,即ng serve,并在浏览器上运行应用程序按预期工作 并且浏览器控制台上也没有错误消息或警告。
但是,我的 vscode 上有一条奇怪的 TSLint 消息说:
[ts] Property 'debounceTime' does not exist on type 'Observable<any>'.
这有点烦人,因为我有点担心有些东西在我不知道的情况下不起作用。
我在这里缺少什么? 谢谢。
【问题讨论】:
-
这不是
TSLint而是TypeScript消息。 -
好吧,这里有什么问题?
-
片段用于可运行示例。对于代码块,使用代码块。
-
@xcode This 可能会有所帮助。
标签: javascript angular typescript rxjs tslint