I have a problem : When I want to create fake users in my database, everything work like a charm until I start the loop 'for'.
At this point, I have this error :
Error adding document: TypeError: Cannot read property 'firestore' of undefined
I've try multiple things but nothing work ... Do you have an idea ?
Thank you all !
create_NewUser(data:any){
this.firestore.collection('Users-test').add({
name:data.name,
town:data.town,
gender:data.gender,
email:data.email,
picture:data.picture,
birthdate:data.birthdate
})
.then(function(docRef) {
// console.log("Document written with ID: ", docRef.id);
let nbInterest:any = data.interests.length;
// let nbAvailaibilities:any = data.interests.length;
for (let index = 0; index < nbInterest; index++) {
this.firestore.collection('Users-test').doc("/" + docRef.id + "/interests/" + index).add({
interest:data.interests[index]
})
}
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
}