Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

$http GET request

  • $http
  • GET
  • CORS
  • Access-Control-Allow-Origin
<script src="../angular/angular.min.js"></script>
<script src="angular_v1_greeting.js"></script>

<div ng-app="DemoApp" ng-controller="DemoController">
        {{greeting}}
        <hr>
    <div ng-show="error">Error! Check the console.</div>
</div>
angular.module("DemoApp", [])
.controller("DemoController", ['$scope', '$http', function($scope, $http) {
    $http.get('http://127.0.0.1:3000/api/v1/greeting').then(
        function(response) {
            console.log(response);
            $scope.greeting = response.data["text"];
            $scope.error = false;
        },
        function(response) {
            console.log("error");
            console.log(response);
            $scope.error = true;
        }
    );
}]);

CORS - Cross-Origin Resource Sharing