【发布时间】:2020-08-03 10:21:51
【问题描述】:
我正在尝试使用下面的 for 循环添加我从 array.length 获得的长度值,但它一直返回 NaN
lent;
ndat:any;
constructor(private afs: AngularFirestore) {
this.afs.collection('Courses').doc(`${firebase.auth().currentUser.uid}`).collection('courses').valueChanges().subscribe(data => {
console.log('my data',data);
this.ndat= data;
this.lent=this.ndat.length;
console.log('my lenthyyyyy',this.lent);
});
for (let i = 0; i < this.dat.length; i++) {
console.log(i+this.lent);
this.ref2=this.afs.collection('Courses').doc(`${firebase.auth().currentUser.uid}`).collection('courses').doc(`Course ${this.lent+i}`);
this.ref2.set({
name: this.dat[i],
progress:'In Progress',
duration:'time'
});
}
}
【问题讨论】:
-
很难说如果你不告诉使用
this和array是什么以及这些调用的上下文。在您的示例中,无需将array.length存储到this
标签: typescript ionic-framework