简体   繁体   中英

displaying the json data in angular2

Here's my json:

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

How can i display the json data in angular 2 using typescript.

{{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. 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.

if your json is valid, you could use JSON.parse to convert it to js Object and use *ngFor to traversal or {{ data | json }} {{ data | json }} to display it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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