title: How to assign property value if not null, to object instance in TypeScript, Angular
body: <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>value: questionsList[key].answer.length&gt;0? null : questionsList[key].answer[0].answerValue
  </code></pre>
  
  <h2>complete code</h2>
  
  <pre><code>if(questionElementType=="textbox")
   {       
  
    var isAnswerExist = questionsList[key].answer.length;
    if(isAnswerExist&gt;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&gt;0? null : questionsList[key].answer[0].answerValue,  // need help here
       required: true,
       order: 5
      }); 
  
      this.mappedQuestions.push(_textBox);
  
   }
  </code></pre>
  
  <h2>Error 1</h2>
  
  <pre><code>formGroup expects a FormGroup instance. Please pass one in.
  
     Example:
  
  
  &lt;div [formGroup]="myGroup"&gt;
    &lt;input formControlName="firstName"&gt;
  &lt;/div&gt;
  
  In your class:
  
  this.myGroup = new FormGroup({
     firstName: new FormControl()
  });
  </code></pre>
  
  <h2>Error 2</h2>
  
  <pre><code>TypeError: Cannot read property 'answerValue' of undefined
  </code></pre>