Javascript firebase数据未添加到阵列3中
这是我的ts文件Javascript firebase数据未添加到阵列3中,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,这是我的ts文件 import * as firebase from 'Firebase'; public items: Array<any> = []; firebase.database().ref('favorite_locations/' + this.key).once('value').then(function(snapshot) { this.items = []; snapshot.forEach( itemSnap =>
import * as firebase from 'Firebase';
public items: Array<any> = [];
firebase.database().ref('favorite_locations/' + this.key).once('value').then(function(snapshot) {
this.items = [];
snapshot.forEach( itemSnap => {
this.items.push(itemSnap.val());
return false;
});
从“firebase”导入*作为firebase;
公共项:数组=[];
firebase.database().ref('favorite_locations/'+this.key)。一次('value')。然后(函数(快照){
此参数为.items=[];
snapshot.forEach(itemSnap=>{
this.items.push(itemSnap.val());
返回false;
});
每次运行应用程序时,显示错误:Uncaught(承诺中):TypeError:无法设置未定义的属性'items'请尝试firebase.database().ref('favorite_locations/'+this.key)。一次('value')。然后((snapshot)=>{})-没有函数()@theridle2谢谢它正在工作