Firebase "once" 事件未 return 承诺
Firebase "once" event does not return promise
在firebase的官方文档中https://www.firebase.com/docs/web/api/query/once.html。写着
Return Value
Returns a Promise that can optionally be used instead of the successCallback and failureCallback to handle success and failure.
但在我的示例代码中,调用一次函数时没有承诺 return
fb.once('value', function(snapshoot){
snapshoot.forEach(function(snap){
var book = new Book(snap);
$scope.bookList.push(book);
$scope.$apply();
});
})
//following lines below cause error because of no promise returned.
.then(function(){
console.log('promise called');
});
请在 jsfiddle 查看完整代码:http://jsfiddle.net/7e4j77q7/5/
我做错了什么?我怎么能让 once 函数 return promise?
您使用的似乎是旧版本的 firebase
,您引用的文档有 2.4.2
版本,而您使用的是旧版本 1.0.11
在firebase的官方文档中https://www.firebase.com/docs/web/api/query/once.html。写着
Return Value
Returns a Promise that can optionally be used instead of the successCallback and failureCallback to handle success and failure.
但在我的示例代码中,调用一次函数时没有承诺 return
fb.once('value', function(snapshoot){
snapshoot.forEach(function(snap){
var book = new Book(snap);
$scope.bookList.push(book);
$scope.$apply();
});
})
//following lines below cause error because of no promise returned.
.then(function(){
console.log('promise called');
});
请在 jsfiddle 查看完整代码:http://jsfiddle.net/7e4j77q7/5/
我做错了什么?我怎么能让 once 函数 return promise?
您使用的似乎是旧版本的 firebase
,您引用的文档有 2.4.2
版本,而您使用的是旧版本 1.0.11