如何在订阅中控制台记录结果? [英] How do i console log the results inside the subscribe?
本文介绍了如何在订阅中控制台记录结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的角度应用程序中,我正在调用服务并获取数据,一旦获取结果,我需要添加控制台日志。我在哪里可以添加控制台日志?
In my angular app i am calling a service and fetching the data, i need to add a console log once the results are fetched. where can i add console log?
this.searchTerm.asObservable()
.debounceTime(300)
.distinctUntilChanged()
.switchMap(term => this.doFind(term))
.subscribe(data => this.results = data
, error => {
this.errorMessage = error;
});
推荐答案
使用代码块
this.searchTerm.asObservable()
.debounceTime(300)
.distinctUntilChanged()
.switchMap(term => this.doFind(term))
.subscribe(data => {
this.results = data;
console.log('data', data);
})
, error => {
this.errorMessage = error;
});
或 do
运算符
this.searchTerm.asObservable()
.debounceTime(300)
.distinctUntilChanged()
.switchMap(term => this.doFind(term))
.do(val => condole.log(val))
.subscribe(data => this.results = data
, error => {
this.errorMessage = error;
});
这篇关于如何在订阅中控制台记录结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文