0

I have $scope.participants = [] as a global variable. My problem is when I used this variable in another function after calling the function below. $scope.participants is empty. However, it isn't when I checked the response.data.

$scope.getParticipants = function(seminar_id,seminar_name,seminar_code) {
    $http({
        method: 'GET',
        dataType: 'JSON',
        params: { 'seminar_id' : seminar_id },
        url: 'getParticipants'
      }).then(function(response) {
          $scope.participants=response.data;
      });
  }
Roger Ng
  • 771
  • 11
  • 28
dan
  • 1

1 Answers1

0

You can check out this working plnkr, you need wait until your promise resolve.

$scope.getParticipants= function(seminar_id,seminar_name,seminar_code){
$http({
    method: 'GET', 
    dataType: 'JSON',
    params: { 'seminar_id' : seminar_id },
    url: 'getParticipants'
  }).then(function(response) {
      $scope.participants=response.data;
      $scope.callBack();
      console.log(response.data);
  });
}
$scope.getParticipants('a','b','c');
raja reddy
  • 372
  • 2
  • 9