[英]Angular $HTTP and Promise
I can't get my promise inside a HTTP.get function to work. 我无法在HTTP.get函数中工作。 When i try to console.log the output, all i get is the promise function?
当我尝试console.log输出时,我得到的只是promise函数?
I am interested in getting the array of events that my api has provided. 我对获取api提供的事件数组感兴趣。
eventApp.factory('LoadEvents', function($http, $q) {
var LoadEvents = function() {
this.events = [];
this.busy = false;
this.after = '';
};
LoadEvents.prototype.nextPage = function() {
if (this.busy) return;
this.busy = true;
var defer = $q.defer();
$http.get('URL inserted here').then(function(response){
defer.resolve(response.data);
});
this.events = this.events.concat(defer.promise);
console.log(this.events);
};
This should be a very basic promise, but i can't figure out why i can't recieve the array instead of the whole promise function? 这应该是一个非常基本的承诺,但是我无法弄清楚为什么我不能接收数组而不是整个promise函数?
By the event array (ie this.event
) if you want to mean the promise array then it should be like this 通过事件数组(例如
this.event
),如果您想表示promise数组,则应该像这样
this.events = this.events.concat([defer.promise]);
or this.events = this.events.push(defer.promise)
then use $q.all(this.events).then(...)
to get all resolved. 或
this.events = this.events.push(defer.promise)
然后使用$q.all(this.events).then(...)
获得所有解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.