I'm trying to create a trigger using angular, but when I get the response from my api it returns me undefined
.
Here's my global-search.ts
file:
export class GlobalSearchComponent{
searchable: String = '';
professionals: any = {};
constructor(public client: Http){
}
getProfessionals() {
return this.client.get('professionals')
.subscribe(data => this.professionals = data.json());
}
doSearch(ev: any) {
let val = ev.target.value;
if(val.length > 3) {
this.getProfessionals();
console.log(this.professionals);
}
}
if in getProfessionals()
method I do:
return this.client.get('professionals'
.subscribe(data => console.log(data.json()));
It returns me an object(and it's right), but in doSearch()
method, it shows me undefined
.
What am I doing wrong?