Having an issue: I successfully create fake users in my database, but encounter a problem when starting the 'for' loop.
The error I'm facing is:
Error adding document: TypeError: Cannot read property 'firestore' of undefined
I've attempted various solutions without success. Any suggestions?
Appreciate any help!
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) {
let nbInterest: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);
});
}