Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Angular 4中拆分JSON对象_Javascript_Json_Angular_Api - Fatal编程技术网

Javascript 如何在Angular 4中拆分JSON对象

Javascript 如何在Angular 4中拆分JSON对象,javascript,json,angular,api,Javascript,Json,Angular,Api,我正在使用一个带有Angular 4前端的JSON API,现在我正在尝试显示这个API的数据 我使用了以下代码: <div *ngFor="let Questionnaire of struc.data"> <span>{{Questionnaire.attributes.content.headline}}</span><br> <span>{{Questionnaire.attributes.content.tex

我正在使用一个带有Angular 4前端的JSON API,现在我正在尝试显示这个API的数据

我使用了以下代码:

<div *ngFor="let Questionnaire of struc.data">
    <span>{{Questionnaire.attributes.content.headline}}</span><br>
    <span>{{Questionnaire.attributes.content.text}}</span><br>
    <span>{{Questionnaire.attributes.content.question}}</span>
</div>

<div *ngFor="let Questionnaire of struc.data">
  <li>{{Questionnaire.attributes.content.answers}}</li>
</div>

{{问卷.属性.内容.标题}
{{问卷.属性.内容.文本}}
{{问卷.属性.内容.问题}
  • {{问卷.属性.内容.答案}
  • 这是可行的,但我的答案是:

    • 吕伯豪普特·尼希特、塞尔滕、艾尼杰·马累、哈菲格、哈菲格
    而不是像这样:

    • 吕贝尔豪普特尼希特
    • 塞尔塞尔滕
    • 艾尼杰男
    • 哈菲格
    • 塞尔胡菲格

    我的代码怎么了

    您可以执行此操作
    问卷.属性.内容.答案.拆分(',')
    ,

    <div *ngFor="let Questionnaire of struc.data">
     <div *ngFor="let ans of Questionnaire.attributes.content.answers.split(',')">
         <li>{{ans}}</li>
      </div>
    </div>
    

    我这样做了,但我遇到了以下错误:无法读取未定义的属性“split”。。我想这是因为我使用的是一个数组,而不是一个字符串,因为我的JSON对象,我只是不知道如何更改它
    <div *ngFor="let Questionnaire of struc.data">
         <div *ngFor="let ans of Questionnaire.attributes.content.answers">
             <li>{{ans}}</li>
          </div>
      </div>