【发布时间】:2019-01-14 02:00:31
【问题描述】:
我的 web 服务返回一个 json 数据,如下所示。
[{ "Key" : 001,
"Record" : {"id":"001",
"name" : "qwerty"}
},
{ "Key" : 003,
"Record" : {"id":"003",
"name" : "asdfg"}
}]
现在我需要以表格格式显示它。通常在 jquery 中,我使用动态创建表并将 div id 分配给表,然后将其替换为动态创建的表。
我的组件.ts:
export class CatComponent extends Lifecycle {
constructor(
private $modal: $ModalManagerService,
private http: HttpClient
) {
super();
}
_initialize(): void {
this.http.get('http://127.0.0.1:3000/query/aa',{responseType:"json"}).subscribe(
response => {
console.log("data :"+response);
var sample=JSON.stringify(response);
});
}
}
$("#divv").html(content);
在 Angular 6 中我应该如何显示?
【问题讨论】:
-
你可以使用
<div id="divv" [innerHTML]='content'></div> -
在html文件中使用*ngFor可以在表格中显示数组数据。
-
在打字稿代码中生成表格不是一个好习惯。
-
@Sujata Chanda 你想让我在 html 中使用这一行吗?
-
是的。如果要在 ts 文件中生成内容,则可以使用上面的 html 创建表。但由于它是 Angular,因此最好像下面的答案一样在 html 中创建整个表格。