2012-11-21 2 views
1

각도 js 앱이 있습니다. 나는 로그인하기 위해 gapi를 사용하고 데이터를 가져 오기 위해 Google 클라우드 엔드 포인트를 호출합니다. 사인 인물은 정상적으로 작동하며 엔드 포인트에서 데이터를 정밀하게 가져옵니다.AngularJS : gapi 클라이언트에서 가져온 데이터가 UI에 표시되지 않습니다.

그러나 데이터를 가져온 후 데이터를 $scope 변수 (UI에 바인딩 됨)에 할당하면 UI가 업데이트되지 않습니다. 심지어 오류가 없습니다. 아래는 나의 코드 스 니펫이다. 어떤 아이디어?

function TestCtrl($scope){ 
    $scope.contactsList = [];//UI template is bound to this list 
//Assuming the gapi client is already loaded 
gapi.client.contactendpoint.list().execute(function(resp) { 
      if (!resp.code) { 
       $scope.contactsList = resp.items;//Does not update ui list 
      } else { 
       alert("Error, response is: " 
        + angular.toJson(resp)); 
      } 
     }); 
} 

감사합니다, 나딤 Ullah

당신은 브라우저 DOM 이벤트에서는 setTimeout, XHR 또는 세 번째에서 예를 들어, 각 프레임 워크의 외부 (의 범위를 업데이트 할 경우) (적용 $ 사용할 필요가

답변

3

파티 라이브러리). 자세한 정보는 http://docs.angularjs.org/api/ng.$rootScope.Scope입니다.

function TestCtrl($scope){ 
    $scope.contactsList = [];//UI template is bound to this list 
    //Assuming the gapi client is already loaded 
    gapi.client.contactendpoint.list().execute(function(resp) { 
    if (!resp.code) { 

     $scope.$apply(function(scope) { 
     scope.contactsList = resp.items; 
     }); 

    } else { 
     alert("Error, response is: " + angular.toJson(resp)); 
    } 
    }); 
} 
+0

감사합니다. Andre Goncalves가 잘하고 있습니다. –

관련 문제