首页 > 解决方案 > Angular HTTP Res JSON 数据以 html 格式打印

问题描述

下面是 HTTP 获取请求响应。我如何使用 *ngFor 在视图中打印相同的内容。我正在尝试在控制台中打印像 data[0].value1 这样的单个对象打印。它返回未定义。内部数据数组 3 个 JSON 对象。还有一些数组

非常感谢任何帮助...

getEmp(){
    this.EmpService.getAccounts().subscribe((res : any[])=>{      
      this.products = JSON.stringify(res);
  });

.

{
        "data": [
            {
                "value1": "3546786908765432",
                "category": "Clothing (Brand)",
                "category_list": [
                    {
                        "id": "001",
                        "name": "Clothing (Brand)"
                    },
                    {
                        "id": "39324324230",
                        "name": "Boutique Store"
                    },
                    {
                        "id": "12342324324",
                        "name": "Website"
                    }
                ],
                "name": "wqeqws",
                "id": "qwsqwsq  w",
                "tasks": [
                    "ANALYZE",
                    "ADVERTISE",
                    "MODERATE",
                    "CREATE_CONTENT",
                    "MANAGE"
                ]
            },
            {
                "value1": "111-9=-09876543",
                "category": "Education",
                "category_list": [
                    {
                        "id": "23456",
                        "name": "Education"
                    }
                ],
                "name": "sdcsfcsdfvsd",
                "id": "111111111111",
                "tasks": [
                    "ANALYZE",
                    "ADVERTISE",
                    "MODERATE",
                    "CREATE_CONTENT",
                    "MANAGE"
                ]
            }
    ],
        "paging": {
            "cursors": {
                "before": "dsfsds",
                "after": "sdfsfs"
            }
        }
    }

标签: jsonangularhttp

解决方案


this.products = res.data;

在您的页面中

< *ngFor="let item of products >

推荐阅读