Angular JS return data from service and Http callback Method
<p>Created a Angular JS service, which sends request to the server for the JSON data. I am able to receive the data correctly in the service, but i am unable to return data to the controller. Please check as follows:</p>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
  
&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;
&lt;body&gt;

&lt;div ng-app="myApp" ng-controller="myCtrl"&gt;

First Name: &lt;input type="text" ng-model="firstName"&gt;&lt;br&gt;
Last Name: &lt;input type="text" ng-model="lastName"&gt;&lt;br&gt;
&lt;br&gt;
Full Name: {{firstName + " " + lastName}}

&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;p&gt;The content is {{content}}&lt;/p&gt;
&lt;/div&gt;

&lt;script&gt;
var app = angular.module('myApp', []);

app.service('MyService', function($http) {
    this.sendRequest = function() {
     $http({
    method: 'GET',
    url: 'http://localhost:3000/json'
  }).then(
   function successCallback(response) {
    console.dir('This is the response');
       console.dir(response);
       return response;
   }, function errorCallback(response) {
       console.dir('This is the error');
       console.dir(response);
       return response;
     }
    );
    };
    this.addition = function(a,b) {
     return a+b;
    }; 
});

app.controller('myCtrl', function($scope, MyService) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
    console.dir(MyService.addition(4,5));
    var a = MyService.sendRequest();
    console.dir("Main program " + a);
    $scope.content = a;
});
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
</p>

<p>For the addition function, i am able to get data correctly (I mean, it is returning sum of 4+5), but coming to the "sendRequest" method, it is invoking the $http call in this method and getting back to the caller "null/empty" data without waiting for the $http method. </p>

<p>Problem is, $http call in the "sendRequest" method is asynchronous (I mean, "then" is called once it is getting the response from the server) and i want to wait for the server response and send response to the caller.     </p>