我'm new to Firebase and Ionic and currently trying to get some data from the server as a certain view is loaded. Right now I am able to get the data inside the service, but I' m无法将获取的 data
作为对控制器的承诺返回 . 这是调用服务的代码:
$scope.$on('$ionicView.beforeEnter', function () {
var user = firebase.auth().currentUser;
fireBaseService.getDataFromDB(user.uid).then(function(res){
console.log(res);
});
以下是调用Firebase API的服务:
this.getDataFromDB = function(uid){
return firebase.database().ref('table/' + uid).on('value', function(snapshot) {
var data = snapshot.val(); //data is available here
return data;
});
}
这是我得到的错误:
TypeError: fireBaseService.getExpensesFromDB(...).then is not a function
1 回答