Angular's $http Service

What's a 'Service'?

Angular services are simply objects that contain some code that can be shared across your app.

We'll talk about Services in detail later this week

Today, we're just going to focus on the $http service

Based on your previous knowledge, what do you think the $http service does?

It's Angular's equivalent to an AJAX call

Let's look at how it's written

First, you need to pass it in as a dependency to your controller

app.controller('someControllerName', function($scope, $http) {

    // Cool controller stuff

});

Next, you need to implement it

app.controller('someControllerName', function($scope, $http) {

    $http.get('URL').then(function(data){
      $scope.view.zenData = data;
    }

});

What does the response look like?

{
  "data":"Keep it logically awesome.",
  "status":200,
  "config": {
    "method":"GET",
    "transformRequest":[null],
    "transformResponse":[null],
    "url":"https://api.github.com/zen",
    "headers":{
      "Accept":"application/json, text/plain, */*"
    }
  },
  "statusText":"OK"
}

Response Body

Response Line

Response Line

Response Headers

What does $http.get() return?

Made with Slides.com