1

Here is my code,

$scope.output=abc(1,2);
    function abc(mid, type) {
       $http({
               ...
             }
           }).then(function (response) {
                return response.data;
          }, function (response) {
         });
      }
    console.log($scope.output)

$scope.output

is

undefined

Function is executing but data is not assigning to $scope variable

0

2 Answers 2

1
abc(1,2);
function abc(mid, type) {
   $http({
           ...
         }
       }).then(function (response) {
            $scope.output = response.data;

      }, function (response) {
     });
  }
console.log($scope.output)

In async operations, you cannot use return

Sign up to request clarification or add additional context in comments.

Comments

0

Instead of using return in async call. You can directly assign the response.data into the $scope.output variable.

abc(1,2);
function abc(mid, type) {
   $http({
           ...
         }
       }).then(function (response) {
            $scope.output = response.data;
      }, function(error) {
     });
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.