Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

Properties HTTP

The server response is an object containing the following properties:

  • .config: the object used to create the request.
  • .data: a string or object holding the server’s response.
  • .headers: a function for retrieving header information.
  • .status: a number representing the HTTP status code.
  • .statusText: a string describing the HTTP status.

Example

var app = angular.module(‘myApp’, []);
app.controller(‘myCtrl’function($scope, $http) {
  $http.get(“welcome.htm”)
  .then(function(response) {
    $scope.content = response.data;
    $scope.statuscode = response.status;
    $scope.statustext = response.statusText;
  });
});

To handle errors, add an additional function to the .then method.

Example

var app = angular.module(‘myApp’, []);
app.controller(‘myCtrl’function($scope, $http) {
  $http.get(“wrongfilename.htm”)
  .then(function(response) {
    // First function handles success
    $scope.content = response.data;
  }, function(response) {
    // Second function handles error
    $scope.content = “Something went wrong”;
  });
});