Рет қаралды 33,336
HTTP services is the important part of any application which communicates with the server. Most front-end applications communicate with backend services over the HTTP protocol.
Use this link to share video: • HTTP Service - Angular...
Till Now we are getting a dummy users data but now we want to get live data somewhere from server
Now we require remote data server which provides HTTP Web Service, which we can call using Angular Front End.
You can create Web Service in any language like Java, PHP, .Net or NodeJS.
We can consume this web service using HttpClient in an angular app.
To keep this demo easy to understand by everyone we will consume a FAKE online web service and you can also test at your end easily :
So use this FAKE online REST API :
jsonplaceholder...
To use HTTP service first step is to enable HTTP Service
.For this we need to include a HttpClientModule in imports array in app.module.ts and this module is defined in library angular/common/http
After this in custom service file (UserService) we need to do Dependency Injection of HttpClient class and with this class make http call using get () method
Angular services return observable in response the way in Angular 1.x it returned promised. Angular services are lazy in nature
Observable are lazy in nature . So if any component want to get Observable it will act like a newspaper. Until unless
you will not subsribe for the newspaper service you will not get that.In same manner until unless you will not subscribe
the Observable you will not call the service .
If you liked my channel , subscribe to it and like my videos. For any queries ask you question in comment section
you can also connect with me @
Facebook: / angularjs4beginners
LinkedIn: / nisha-singla-82407aa0
Website :