So I am trying to subscribe to a simple service that return data from a local JSON file.
I have managed to get the service working, I can log it out in the function
Maybe some pictures help?
The numbers here indicate the order of operations.
Send the Http Request
subscribe on the returned Observable.get request is submitted to the server for processing.ngOnInit method is complete.Any code here after the subscribe cannot access the movies property since the data has not yet been returned.
Receive the Http Response
At some LATER point in time ...
Attempting to access the movies property prior to step #8 results in an error.
Can we access the value here? NO
To fix it: