not able to access $scope object outside a http response callback function in angularjs

后端 未结 3 1969
野趣味
野趣味 2021-01-17 02:51

I have this controller for saving some details for an individual. I have a separate repository EntityRepository where a function to get the user gender from database is defi

3条回答
  •  梦谈多话
    2021-01-17 03:07

    Can you try this.

      $scope.GetUserGender = function(){
     EntityRepository.getUserGender().then(function(response){
        $scope.userGender = response.data.gender;
        console.log("inside : ", $scope.userGender);
      }).catch(function(errorResponse) {
        $scope.error = errorResponse.data
      });     
    }
      $scope.GetUserGender();   //
    
     console.log("outside : ", $scope.userGender);
    

    Hope this will work :)

提交回复
热议问题