I looping through array of object and creating instance of specific class, followed by assigning values accordingly. Everything working fine, expect I need to check if value does exist then only assign.
In my scenario, I have list of questions which may or may not have answer so to check and assign value if not null, I doing following code but throwing error.
value: questionsList[key].answer.length>0? null : questionsList[key].answer[0].answerValue
complete code
if(questionElementType=="textbox")
{
var isAnswerExist = questionsList[key].answer.length;
if(isAnswerExist>0) // this one does work
{
var ans = questionsList[key].answer[0].answerValue;
console.log("answer ", ans);
}
let _textBox = new TextboxQuestion({
questionId: questionsList[key].questionId,
questionElementType: questionsList[key].questionElementType[0].title,
questionType: questionsList[key].questionType,
title:questionsList[key].title,
displayId: questionsList[key].displayId,
key: questionsList[key].questionId,
label: questionsList[key].title,
value: questionsList[key].answer.length>0? null : questionsList[key].answer[0].answerValue, // need help here
required: true,
order: 5
});
this.mappedQuestions.push(_textBox);
}
Error 1
formGroup expects a FormGroup instance. Please pass one in.
Example:
<div [formGroup]="myGroup">
<input formControlName="firstName">
</div>
In your class:
this.myGroup = new FormGroup({
firstName: new FormControl()
});
Error 2
TypeError: Cannot read property 'answerValue' of undefined
value: questionsList[key].answer.length>0? questionsList[key].answer[0].answerValue : null // need help here