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;
});
Use a code block
this.searchTerm.asObservable()
.debounceTime(300)
.distinctUntilChanged()
.switchMap(term => this.doFind(term))
.subscribe(data => {
this.results = data;
console.log('data', data);
})
, error => {
this.errorMessage = error;
});
or the do operator
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;
});
You are using the shorthand version of the arrow function, use the bigger version :)
.subscribe((data) => {
this.results = data;
console.log(data);
}, error => {
this.errorMessage = error;
});
u can do like this
this.searchTerm.asObservable()
.debounceTime(300)
.distinctUntilChanged()
.switchMap(term => this.doFind(term))
.subscribe(
data=>this.message=data.msg,
error=>alert('errer'),
()=>{console.log('finished');}
);