在我的角度应用程序中,我正在调用服务并获取数据,我需要在获取结果后添加控制台日志。我在哪里可以添加控制台日志?
this.searchTerm.asObservable()
.debounceTime(300)
.distinctUntilChanged()
.switchMap(term => this.doFind(term))
.subscribe(data => this.results = data
, error => {
this.errorMessage = error;
});
答案 0 :(得分:7)
使用代码块
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;
});
答案 1 :(得分:3)
您正在使用箭头功能的简写版本,请使用更大的版本:)
.subscribe((data) => {
this.results = data;
console.log(data);
}, error => {
this.errorMessage = error;
});
答案 2 :(得分:1)
this.searchTerm.asObservable()
.debounceTime(300)
.distinctUntilChanged()
.switchMap(term => this.doFind(term))
.subscribe(
data=>this.message=data.msg,
error=>alert('errer'),
()=>{console.log('finished');}
);