Log*_*n_B 11 rxjs typescript angular
我正在尝试将我的应用程序从Angular 5升级到Angular 6.我按照https://update.angular.io/上的步骤进行操作 .至少我认为我做了.
错误是:
Property 'debounceTime' does not exist on type 'Subject<string>'.
Run Code Online (Sandbox Code Playgroud)
我的组件也丢失了debounceTime导入.我认为ng更新删除了它.
Log*_*n_B 16
我在@ Siva636和@Andrew Lobban的帮助下解决了这个问题.
我需要使用管道:
this.field$.pipe(
debounceTime(400),
distinctUntilChanged())
Run Code Online (Sandbox Code Playgroud)
小智 6
从Angular 6.1.8开始,仅需要像下面的示例一样导入和添加管道
import {debounceTime} from 'rxjs/operators';
Run Code Online (Sandbox Code Playgroud)
然后在可观察的订阅方法调用管道(debounceTime(1000))之前的字段上,如下所示:
emailControl.valueChanges.pipe(debounceTime(1000)).subscribe(value => this.setMessage(emailControl));
Run Code Online (Sandbox Code Playgroud)
就是这样,这只是@tiago答案的更新答案-她在其中定义const debouncetime-我们实际上并不需要使用const和pipe。
在reactx文档之后,您还应该订阅可观察的管道:
.pipe(
debounceTime(500),
distinctUntilChanged(),
map((val) => {
...
})
)
.subscribe();
Run Code Online (Sandbox Code Playgroud)
如果一个Observable在观察者订阅之前没有开始发出项目,则称为“冷” Observable。
归档时间: |
|
查看次数: |
12518 次 |
最近记录: |