When connecting to my data from Firebase, I noticed that using the elvis operator
is essential to avoid encountering undefined
errors. Recently, as I delved into creating reactive forms, I encountered an issue with a component I developed that fetches actual data from Firebase. The problem arises when working with the FormGroup
, and here is a snippet of the code:
createForm() {
this.quesForm = this.fbuild.group({
question: this.featureQuestion.question,
id : this.featureQuestion.id,
name : this.featureQuestion.name,
answers : this.fbuild.array([])
});
this.setAnswers(this.featureQuestion.answers);
}
Upon attempting to address the issue by including the elvis operator
as shown below:
createForm() {
this.quesForm = this.fbuild.group({
question: this.featureQuestion?.question,
id : this.featureQuestion?.id,
name : this.featureQuestion?.name,
answers : this.fbuild.array([])
});
this.setAnswers(this.featureQuestion?.answers);
}
I encountered additional errors indicating that an expression or punctuation such as ;
and ,
was expected on every line. It became evident that simply adding the ?
does not function the same way within the script compared to the template. How can I resolve this issue effectively?