$http

The $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser XMLHttpRequest object or via JSONP. The $http API is based on the deferred/promise APIs exposed by the $q service.

$http shortcut method are:

  • $http.get
  • $http.head
  • $http.post
  • $http.put
  • $http.delete
  • $http.jsonp

The returned value of calling $http is a promise, you can use the then method to register callback. These callbacks receive a single argument an object representing the response.

index.html

<!DOCTYPE html>
<html ng-app='app'>

<head>
  <link rel="stylesheet" href="style.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
  <script src="script.js"></script>
</head>

<body>
  <div ng-controller="HelloCtrl">
    <ul>
      <li ng-repeat="user in users">{{user.name}}</li>
    </ul>
  </div>
</body>

</html>

app.js

var app = angular.module('app', [])
  .controller('HelloCtrl', ['$scope', '$http', function($scope, $http) {
    $http.get('http://jsonplaceholder.typicode.com/users').success(function(data) {
        console.log(data);
        $scope.users = data;
    });
  }]);