首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何解析角7中的json?

如何解析角7中的json?
EN

Stack Overflow用户
提问于 2019-03-04 01:29:05
回答 2查看 5K关注 0票数 0

我有来自我的节点rest的以下输出:

代码语言:javascript
复制
{
    "workorder": [
        {
            "id": 1,
            "Workorderno": 110,
            "Nfno": 23,
            "Amount": 230,
            "Orderno": 34,
            "createdAt": "2019-03-02 00:19:49.495 +00:00",
            "updatedAt": "2019-03-02 12:40:36.647 +00:00"
        }
    ]
}

我想使用角7读取输出并将其显示在表中?有人能指导我做那件事吗?我试着修改rest,但是失败了,我可以得到结果。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-04 01:30:59

您需要这样的东西使用ngFor

代码语言:javascript
复制
<table class="table table-striped">
        <thead>
            <tr>
                <th>Id</th>
                <th>Workorder No</th>
            </tr>
        </thead>
        <tbody>
           <tr *ngFor="let work of data.workorder">
            <td>{{work?.id}}</td>
            <td>{{work?.Workorderno}}</a></td>
           </tr>
        </tbody>
    </table>
</div>

你的界面应该是这样,

代码语言:javascript
复制
  export interface Workorder {
        id: number;
        Workorderno: number;
        Nfno: number;
        Amount: number;
        Orderno: number;
        createdAt: string;
        updatedAt: string;
    }

然后在你的身体里,

代码语言:javascript
复制
  data : Workorder;
  constructor(private service: nowService) {

  }

  ngOnInit() {
    this.service.getAll().subscribe((data) => {
       this.data = data;
    })
  }
}
票数 1
EN

Stack Overflow用户

发布于 2019-03-04 06:54:19

尝试添加到tr标记: ngIf="data.workorder!=null“

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54975509

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档