我正在学习 AngularJS 和 Firebase 并使用 AngularFire 0.8.2(我知道旧)。我想要一个函数(getAccount)从firebase返回一个与initAccount相同的数组。firebase URL 有效,但我不知道如何使函数返回数组。任何帮助,将不胜感激 :)
app.service('DataService', function(FURL, $firebase) {
var ref = new Firebase(FURL);
//initial account array to load
this.account = [
{'info':'Sig1'},
{'info':'Sig2'},
{'info':'Sig3'}
];
this.getAccount = function(user) {
var uid = user.uid;
var dir = 'profile/' + uid + '/account';
var accountSigs = $firebase(ref.child(dir)).$asArray().$loaded().then(function(response) {
//show response returns [[object Object],[object Object],[object Object]] with correct data as it should.
console.log('show response: [' + response + ']');
return response;
});
// this returns [[object Object]] but I don't know why
console.log('show accountSigs: [' + accountSigs + ']');
return accountSigs;
};
});