Cloud AngularJS:gapi客户端获取的数据不会显示在UI上
我有一个角度js应用程序。我正在使用gapi登录,然后调用我的google云端点获取数据。登录功能工作正常,并且可以从端点很好地获取数据 但是在它获取数据之后,如果我将数据分配给Cloud AngularJS:gapi客户端获取的数据不会显示在UI上,cloud,angularjs,endpoints,Cloud,Angularjs,Endpoints,我有一个角度js应用程序。我正在使用gapi登录,然后调用我的google云端点获取数据。登录功能工作正常,并且可以从端点很好地获取数据 但是在它获取数据之后,如果我将数据分配给$scope变量(绑定到UI),它不会更新UI。甚至没有错误。下面是我的代码片段。有什么想法吗 function TestCtrl($scope){ $scope.contactsList = [];//UI template is bound to this list //Assuming the gapi cl
$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));
}
});
}
问候,,
Nadeem Ullah如果希望从angular框架外部(例如从浏览器DOM事件、setTimeout、XHR或第三方库)更新范围,则需要使用$apply()。
更多信息请访问
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));
}
});
}