The server response is an object containing the following properties:
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.
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”; }); }); |