top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How do we make HTTP get and post calls in Angular?

+1 vote
327 views
How do we make HTTP get and post calls in Angular?
posted Jan 10, 2017 by Sahana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

To make HTTP calls we need to use the “$http” service of Angular. In order to use the http services you need to make provide the “$http” as a input in your function parameters as shown in the below code.

function CustomerController($scope,$http)
{
    $scope.Add = function()
    {
            $http({ method: "GET", url: "http://localhost:8438/SomeMethod"     }).success(function (data, status, headers, config)
        {
                   // Here goes code after success
        }
    }
}

“$http” service API needs atleast three things:

First what is the kind of call “POST” or “GET”.

Second the resource URL on which the action should happen.

Third we need to define the “success” function which will be executed once we get the response from the server.

$http({ method: "GET", url: "http://localhost:8438/SomeMethod"    }).success(function (data, status, headers, config)
{
// Here goes code after success
}
answer Jan 11, 2017 by Manikandan J
...