0

Hi I have JSON data in below format. I want to render it in HTML page using angular.

questionarie = [{
   qText : " Issue Type",
   options : ["Functional Issue" , "Performance Issue" , "Crash Issue" , "Diagnostic Issue"],
   questionId : "1001",
   "parentId" : "",
   childs : [{
      qText : " Issue Type",
      options : ["Functional Issue" , "Performance Issue" , "Crash Issue" , "Diagnostic Issue"],
      questionId : "1001_1",
      "parentId" : "1001",
      childs : []
   }]
}];

I tried all below option.

   <ul>
        <li *ngFor=" let item of questionnaries; let ind = index">{{item.qText}} 
            <ul>
                <li *ngFor=" let option of item.options; let optionIdx = index ">{{option}} {{ind2}} 
                  <ul ng-if="post?.capabilities?.item.childs[optionIdx]?.length > 0 ; let child = item.childs[optionIdx]; ">
                    <li >{{child.qText}}</li>
                  </ul>
               </li>
            </ul>

I am getting below error in browser console:

ERROR TypeError: Cannot read property qText of undefined

1
  • 1
    Your variable name is questionarie but you are accessing questionaries in your html Commented Oct 9, 2019 at 10:50

2 Answers 2

1

ng-if is AngularJs, Angular uses *ngIf

You are iterating questionnaries but your array is called questionarie

Have you tried using

item.childs[optionIdx].qText

Rather than trying to let a view variable.

What is post?

Is this what you are looking for https://stackblitz.com/edit/angular-n5abdx?file=src%2Fapp%2Fapp.component.html

Sign up to request clarification or add additional context in comments.

Comments

1

Your variable name is questionarie but you are accessing questionaries in your html

1 Comment

I tried item.childs[optionIdx].qText and let child = {tem.childs[optionIdx]} then using {{ child.qText}} . I have corrected json object name questionarie this not the problem. problem is in nested <li >{{child.qText}}</li> if I use only <li >{{child}}</li> html UI shows [object object] it means object is there but it is not typedcased to json equivalent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.