2016-06-22 3 views
2

저는 각도 조절기와 각도 서비스를 가지고 있습니다. 내 컨트롤러에서 나는 서비스에 전화하고 있습니다. 내 서비스에는 두 가지 기능이 있습니다. 첫 번째 함수는 정상적으로 작동합니다. 그러나이 문제는 두 번째 문제에서 발생합니다. 다음은 관련 함수에 대한 코드입니다. 내 첫 번째 기능은 잘 작동하기 때문에 컨트롤러에서 해당 서비스의 함수를 호출하는 코드에 따라

function getCurrentUser() { 
    return $resource(_URLS.BASE_API + 'get_current_user' + _URLS.TOKEN_API + $localStorage.token).get().$promise; 
} 

,

//Get current user id 
$scope.getCurrentUserId = function() { 
    ParentService.getCurrentUser.then(function(response) { 
     if (response.query_status == "success") { 
      $scope.userid = response.data.id; 
      console.log('Value is: '+ $scope.userid); 
     } else { 
      $scope.userid = null; 
     } 
    }, function(error) { 
     $scope.userid = null; 
     console.log("Error : Failed to load user data..."); 
     console.log(error); 
    }); 
}; 

나는 문제가 무엇인지 알아낼 수 없습니다. 누군가가 나를이 문제를 해결하는 데 도움이되기를 바랍니다.

답변

3

컨트롤러 코드는 다음과 같아야합니다. ()ParentService.getCurrentUser()

$scope.getCurrentUserId = function() { 
    ParentService.getCurrentUser() // notice the "()" here 
    .then(function(response) { 
     ... 
    }, function(error) { 
     ... 
    }); 
}; 
관련 문제