作为我之前的问题(我无法遍历一个看起来已满的数组)的后续问题,我现在已经知道问题是什么,应该是这个列表当我开始使用它时没有满。FirebaseListObservable + Promise =? (AngularFire2)
然后我尝试使用promise来等待任务异步执行,然后继续。
事情是,对我来说,承诺语法是真的放弃,似乎太复杂了像我这样的人,基本上从来没有在这个项目之外使用JavaScript。
我有这样的承诺:
var promise=new Promise(function(resolve,reject){
that.af.database.list('/users/'+that.authentificationService.getUserId()+'/favs'/*, { preserveSnapshot: true}*/)
.subscribe(snapshots=>{
snapshots.forEach(snapshot => {
//console.log(snapshot.label);
that.prefList.push(snapshot.label);
//this.prefList.push(snapshot.label);
});
});
console.log("promise = done");
return that.prefList;
});
(即==这,顺便说一句)
我得到的 “完成” 的打印,但我不知道这是相关
然后我尝试在承诺的功能之内做一些事情:
promise.then(function(result){ (...) }
我有多个console.l里面有ogs,但没有一个实际执行。我究竟做错了什么?
promise.catch(function(e){
console.log("catch entered");
console.log(e);
});
捕获不会记录任何东西到控制台。
你救了我:) – Steve