filmov
tv
How to make an Angular HTTP GET Request
Показать описание
This confuses all new Angular Developers.
Using the built-in Angular HTTP client doesn't work the way you might expect.
Most libraries that make network requests will return Promises when fetching data because it's an asynchronous action right? Angular likes to be different and each of the methods on the Angular HTTP service don't return Promises.
They return RxJS Observables instead.
This means you can't use the shorthand `async/await` keywords or access a `.then` property (if you're not into the whole brevity thing) on the returned object, you need to `subscribe` to the Observable returned instead.
Inside the subscription you can get the results from the network call from the `next` property and `error` will give you any errors thrown when making the call.
Using the built-in Angular HTTP client doesn't work the way you might expect.
Most libraries that make network requests will return Promises when fetching data because it's an asynchronous action right? Angular likes to be different and each of the methods on the Angular HTTP service don't return Promises.
They return RxJS Observables instead.
This means you can't use the shorthand `async/await` keywords or access a `.then` property (if you're not into the whole brevity thing) on the returned object, you need to `subscribe` to the Observable returned instead.
Inside the subscription you can get the results from the network call from the `next` property and `error` will give you any errors thrown when making the call.