0

Hi all i am new to Angular JS. I have written a factory and a function to call the factory. I am puzzled how angular prcocesses the function calls. In the code below I make a reference to the respone variable flightData. I have the function to call the factory and set the response then i call said function and check the resonse on the variable. Before the function call i check the variable and it returns undefined as expected. After I call the function unexpectedly it refurns undefined. However when the function runs inside it will return the expected result. Can some one point me in the right direction on how Angular JS processes this?

$scope.getFlightDetail = function (flight_id) {
    dataFactory.getFlightDetail(flight_id)
        .then(function (response) {
            $scope.flightData = response.data;
            console.log("Inside")
            console.log($scope.flightData)
        }, function (error) {
            $scope.status = 'Unable to load data: ' + error.message
        })
  }
  console.log("Before")
  console.log($scope.flightData)
  $scope.getFlightDetail(flight_id)
  console.log("After")
  console.log($scope.flightData)
beepboop
  • 57
  • 6

0 Answers0