In my Angular app, I am subscribing to an Observable below:
ngOnInit() {
let readerID: number = parseInt(this.route.snapshot.params['id']);
this.dataService.getReaderById(readerID)
.subscribe(
(data: Reader) => this.selectedReader = data,
(err: any) => console.log(err)
);
console.log('SELECTED READER: ' + this.selectedReader); }
When the user moves to this page, a Reader ID is passed in the route & populates some input fields with that Reader info.
But, this is also logged to the console:
SELECTED READER: undefined
I thought that my code was meant to assign the retrieved data to the selectedReader variable, so I'm not sure why it's logging as UNDEFINED.
Can someone please tell me why this is happening, even though the reader details are being displayed? Why is the selectedReader actually undefined?