약속 값은 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;
}
내가 잘못하고있는 것이 있습니까?