Yoa*_*adi 6 javascript jsonp angularjs angular-promise google-sheets-api
Angular 1.6的$ http.jsonp与google sheet的API不太搭配:
我正在尝试从谷歌工作表中获取并获取我的数据,具体如下:
var callback;
app.controller("meetingsTable", function ($scope, $http, $sce) {
var url = "http://spreadsheets.google.com/a/google.com/tq";
var trustedUrl = $sce.trustAsResourceUrl(url);
var key = 'MY_KEY';
var tq = 'select%20*%20limit%2010';
var tqx = 'responseHandler:callback';
var params = {
key: key,
tq: tq,
status: 'ok',
tqx: tqx
};
callback = function (response) {
console.log(response); // entering here, not to the promise
return response;
}
$http.jsonp(trustedUrl, { params: params }).then(function (response) {
console.log(response);
retrun;
//success things go here
}, function (response) {
//error things go here
});
});
Run Code Online (Sandbox Code Playgroud)
我成功地通过使用函数(回调)和vnila js从表单中获取数据,当我尝试使用angular时,我在源代码中得到了一个"google.visualization.Query.setResponse"对象,控制台错误:未捕获的ReferenceError:未定义谷歌.
最讨厌的事情 - 承诺没有回复响应,我无法更新我的表的值ansyc.我尝试了所有我能想到的(以及stackoverflow中的每个建议),我尝试过的事情:
如果我记得更多的东西,我会在下面更新.
拜托,任何人都可以找出问题所在吗?非常感谢,谢谢,Yoav.
回答我自己的问题:
如果你们有同样的问题,请使用 Angular 的$scope.$apply属性。这是 Angular 的 API 中没有详细记录的属性,因此这里有一个很好的指南, 说明如何使用 $apply,并提供了一个很好的示例。我的实现:
$scope.tableContentData;
callback = function (response) {
$scope.$apply(function () {
$scope.tableContentData = response;
});
};
$http.jsonp(trustedUrl).then(function () {
//success stuff
}, function () {
//error stuff
});
Run Code Online (Sandbox Code Playgroud)
当我在控制器外部声明回调时。
这是一场噩梦。
无论如何,感谢您的投票!
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |