In below AngularJS controller:
- Initially I declared 2 global variables, xandy
- Then I perform an AJAX call using $http.get()and I got the correct response from the backend, and kept the required response values in variablesxandy.
- In an alertmessage I am trying to print the values ofxandy.
I have gone through other question and answers in Stack Overflow and it is a duplicate question, but it's not successful here.
app.controller('MyController', function($scope, $http, $rootScope) {
    $scope.x = '';
    $scope.y = '';
    $http.get('javaAngularJS').then(function (response) {
        var data = response.data;
        $scope.smsresult = data;
        //need to print following x and y values in below alert message
        $scope.x = $scope.smsresult.failure;
        $scope.y = $scope.smsresult.success;
    });
    alert(x+"   "+y);
});
But in the alert message, the values of x* and y are not printing.  What's my mistake  in above code?
 
     
     
     
    