約束の値がconsole.log
のとき、値は取得されますが、長さは0を返します。値を警告すると、約束は返されますが、空です。プロミス値の長さが0を返す
this.findClosestRiderToUser().then(data => {
console.log(data);
//alert (data) not working , returns empty
//console.log(data.length) returns 0
})
//here is the promise code
findClosestRiderToUser(){
var promise = new Promise((resolve, reject)=> {
this.fetchAllRiders().subscribe(distance => {
this.distances.push(distance);
});
resolve(this.distances);
})
return promise;
}
私が間違っていることはありますか?