I'm getting valid response value from subscriber when I use below code snippets from two different components.
dataService.ts
insertappFormData(){
return this.http.get('http://localhost:48116/RecuruitmentService.asmx/addRoleTest?i=3').map(this.extractData);
}
private extractData(res: Response) {
return res.text() ? res.json() : {};
}
app.component.ts
this.dataService.insertappFormData().subscribe((response) => console.log(response));
console output
When I'm trying to assign a variable to response value I'm getting 'undefined' error.
myvar:any;
this.dataService.insertappFormData().subscribe(response => this.myvar = response);
console.log(this.myvar);
I have already go through the below discussions. Solution-1 , Solution-2
But I couldn't solve it. How to solve this problem?