Angularjs. Services. $http service

Главная » Tutorials » JavaScript » 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.

In some cases services are similar on javascript build-in objects. For example, $http service is analog of XMLHttpRequest (XHR) in javascript. But there is one important difference – services in angular are not global objects. It’s not the same in javascript.
$http service has got several methods, which illustrate requests types:

  • $http.get(url, config)
  • $, 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

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This