I'm having a problem with the subscribe method, I'm receving the data, when i put a console.log to see whats in that variable, it works but if I do the same outside that method it says undefined, any ideas why does this happend?
planificadorD: any;
constructor(private auth: AuthService, private toastService: ToastService,
private router: Router, private planificadorService: PlanificadorService) {
}
ngOnInit() {
if (this.postData) {
this.planificadorService.planificadorData(this.postData).subscribe((res: any) => {
this.planificadorD = res.planificadorData;
console.log(this.planificadorD); //this works
});
}
console.log(this.planificadorD); //this does not ->undefined
}
My service
planificadorData(postData: any): Observable<any> {
return this.httpService.post('planificador_get', postData);
}