I want to create a radio button alert by using the data in fireStore. I generated an observable by valueChanges() but console.log returns Undefined when I used it in the function that can't read the data and eventually cannot insert the values for radio button. I am new to fireStore and ionic.
I have also tried using .get().then(function(doc) but returns error as not a function. I have also tried using subscribe() but also not able to give me the actual data, or I have missed something. I have google for many days but just can't find the solution. I hope somebody could help.
myMemberList = [];
constructor(public navCtrl: NavController,
public alertCtrl: AlertController,
public firestore: AngularFirestore,
public afAuth: AngularFireAuth,
) { }
ionViewDidEnter() {
this.afAuth.authState.subscribe(user => {
if (user) {
this.userId = user.uid;
this.fireStoreTaskList = this.firestore.doc<any>('users/' +
this.userId).collection('Member').valueChanges();
}
});
}
// create the inputs for radio button //
createInputs() {
const theNewInputs = [];
for (let i = 0; i < this.fireStoreTaskList.length; i++) { // undefined
theNewInputs.push(
{
type: 'radio',
label: this.fireStoreTaskList.memberName, // undefined
value: this.fireStoreTaskList.memberId, // undefined
checked: false
}
);
} {
console.log(theNewInputs);
}
return theNewBeneInputs;
}
// Radio button alert to choose data //
async selectMember() {
this.myMemberList = this.createInputs();
const alert = await this.alertCtrl.create({
header: 'Member',
inputs: this.myMemberList,
buttons: [{ text: 'Cancel', role: 'cancel' },
{ text: 'OK',
handler: data => {
console.log(data)
}
}
]
});
await alert.present();
}