Exploring Angular and TypeScript, I am currently delving into the concepts of HttpClient, observables, and subscribe.
When I include the following code in a component function:
console.log(this.http.get('assets/user.json'));
I receive an object but do not see any network request to
https://localhost:4200/assets/user.json
in the debugger's network
tab. However, if I modify the code to:
this.http.get('assets/userDetail.json').subscribe(data => this.user = { name: data['name'] });
I can observe the network request being made to the specified URL. Why does this occur? My initial assumption was that
this.http.get('assets/userDetail.json')
would trigger the request even without explicitly subscribing to the response data stream.