I'm trying to get data from firestore database and using *ngFor
directive to display the data in Ionic 4. When I check the console, it shows an error TypeError: Cannot read property 'todoList' of undefined
. Need help.
todo.ts
ngOnInit(): void {
const todoList= [];
var userid = this.afAuth.auth.currentUser;
var getid = userid.uid;
console.log(getid);
this.afs.firestore.collection('todos')
.where('userID', '==', getid)
.get()
.then(function(querySnapshot){
querySnapshot.forEach(doc=>{
console.log(doc.id, "=>", doc.data());
this.todoList.push({
id: doc.id,
Title: doc.data().title,
Description: doc.data().desc,
})
});
}).catch(function(error){
console.log(error);
})
}
At this point, I'm not sure what I did wrong.
todo.html
<div *ngFor="let todo of todoList">
<div class="user">
<span> {{ todo.Title }} </span>
<p>{{ todo.Description }}</p>
</div>
</div>
The 'todo.html` page is blank.