Angularjs. Services. $http service
Today we’ll consider services in angular on the example of $http service. $http is one of the powerful and important services in angular. It lets developer to communicate with server. Also it helps to make cross domain requests.
$http service has got several methods, which illustrate requests types:
- $http.get(url, config)
- $http.post(url, data, config)
- $http.put(url, data, config)
- $http.delete(url, config)
- $http.jsonp(url, config)
- $http.head(url, config)
- $http.patch(url, data, config)
Accordingly, each of these methods accepts 2 or 3 parameters: url – request address; data – data, which you send to the server; config – additional information for request.
It’s not required to call some of these methods to do request. You can make request, call $http as a method, pass to it config object. In the code below I shew both ways.
Also I notice, with $http it is possible to make cross domain requests. For this $http has got jsonp method.
You cand read more about $http service here
Homework for you will be next task – you must make post request (save data from our app form).
Send me your results to firstname.lastname@example.org