我似乎从gapi.client.client.drive.files.list中获得了奇怪的行为,我无法从其返回的承诺中更新范围。
angular.module('myApp').controller("folder_controller", function($scope, $q, $http, $rootScope) {
$scope.list_subfolders = function () {
gapi.client.drive.files.list({
'q': "mimeType = 'application/vnd.google-apps.folder'",
'fields': "nextPageToken, files(id, name, parents, mimeType, description, starred, properties)"
}).then(function(response) {
$scope.subfolders = response.result.files;
console.log($scope.subfolders);
}, function(error){
console.log(error);
});
}
});
当我运行listrongubfolders()... console.log显示$ scope.subfolders可以...但是视图永远不会使用该值更新 - 它是空的。我尝试了各种事情,包括仅分配给$ rototscope,但是我无法获得使用$ scope.subfolders的视图。
。我在做错了吗?我不明白为什么该变量没有更新。
尝试以下:
angular.module('myApp').controller("folder_controller", function($scope, $q, $http, $rootScope) {
$scope.list_subfolders = function () {
gapi.client.drive.files.list({
'q': "mimeType = 'application/vnd.google-apps.folder'",
'fields': "nextPageToken, files(id, name, parents, mimeType, description, starred, properties)"
}).then(function(response) {
$scope.subfolders = response.result.files;
// you need to refresh the view:
$scope.$apply();
console.log($scope.subfolders);
}, function(error){
console.log(error);
});
}
});