angular 5 display nested questions and answer show item under it parent item

前端 未结 3 464
甜味超标
甜味超标 2021-01-22 09:37

this is my server response for quetions and answers.. its a array.

[
    {
        \"id\": 1,
        \"product\": 1,
        \"user\": \"alex\",
        \"text\         


        
3条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 10:16

    Accepted answer Working for one level question. If really want to work in nested scenario: Please check below option

      export class QuestionList
      {
        questions:Question[];
      }
    
      export class Question
      {
       text:string;
       answer:Answer;
       nextquestions:QuestionList;
     }
    
    export class Answer
    {
      text:string;
    }
    
    
    @Component({
     selector: 'question-view',
     template: `
    • {{q.text}}:{{q.answer.text}}
    ` }) export class QuestionViewComponent { @Input() questions: any[]; }

提交回复
热议问题