简体   繁体   English

在angular2中显示json数据

[英]displaying the json data in angular2

Here's my json: 这是我的json:

groups=[
  {
    ["red pencil","blue pencil","yellow pencil"]
  },
  {
    ["big rubber","small rubber"]
  },
];

How can i display the json data in angular 2 using typescript. 我如何使用打字稿以角度2显示json数据。

{{groups | json}}

or 要么

<div *ngFor="let g of groups">
  <div>Group:</div>
  <div *ngFor="let i of g">{{i}}</div>
</div>

JSON is similar to JavaScript's way of writing arrays and objects, with a few restrictions. JSON与JavaScript编写数组和对象的方式类似,但有一些限制。 All property names have to be surrounded by double quotes, and only simple data expressions are allowed—no function calls, variables, or anything that involves actual computation. 所有属性名称都必须用双引号引起来,并且仅允许简单的数据表达式-不允许使用函数调用,变量或涉及实际计算的任何内容。 Comments are not allowed in JSON. JSON中不允许注释。

if your json is valid, you could use JSON.parse to convert it to js Object and use *ngFor to traversal or {{ data | json }} 如果您的json有效,则可以使用JSON.parse将其转换为js对象,并使用*ngFor进行遍历或{{ data | json }} {{ data | json }} to display it. {{ data | json }}进行显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM