I am trying to use a GET request to receive data to put into a local variable. I have been able to get the local variable to display its data in the console admin if this is within the subscibe code. However, when i place the console.log outside, it does not work. Why is "this.taskSchedule" not displaying in the console?
export class TestTaskComponent implements OnInit {
profileForm: FormGroup;
taskSchedule: any = {};
constructor(
private taskScheduleService: TaskScheduleService,
private stateStorageService: StateStorageService,
private router: Router) { }
ngOnInit() {
this.taskId = this.stateStorageService.getCurrentTaskId();
this.taskScheduleService.getTaskSchedule(19).subscribe(data => {
this.taskSchedule = data;
});
console.log(this.taskSchedule);
}
}
In the console output, it just says "undefined". It should output the API data