角度-如何将接收到的JSON传递到html表?

角度-如何将接收到的JSON传递到html表?,html,json,angular,typescript,angular-material,Html,Json,Angular,Typescript,Angular Material,我有一个Angular 6项目,我收到一个JSON对象,如下所示: 现在我想在一个html表中注入/传递它。这是我的密码: 接口 接口Ilivelog{ 灌输:字符串; procID:string; threadNum:字符串; 状态:字符串; } 对象 dataAgent:Ilivelog; 方法 onGetAgent(){ this.backend.getAgentStatus().subscribe( (回复:回复)=>{ this.dataAgent=response.json()

我有一个Angular 6项目,我收到一个JSON对象,如下所示:

现在我想在一个html表中注入/传递它。这是我的密码:

接口

接口Ilivelog{
灌输:字符串;
procID:string;
threadNum:字符串;
状态:字符串;
}
对象

dataAgent:Ilivelog;
方法

onGetAgent(){
this.backend.getAgentStatus().subscribe(
(回复:回复)=>{
this.dataAgent=response.json();
log(“欠费代理:+this.dataAgent”);
},
(错误)=>{
console.log(错误)
}
)
}
我如何获取数据

getAgentStatus(){
返回此.http.get('http://localhost:8081/rms_agent/status');
}

如何将此json传递到HTML表中?

在组件模板中尝试以下操作:

<table border="1">
  <thead>
    <td>instID</td>
    <td>procID</td>
    <td>threadNum</td>
    <td>status</td>
  </thead>
  <tbody>
    <tr *ngFor="let item of dataAgent">
      <td>{{item.instID}}</td>
      <td>{{item.procID}}</td>
      <td>{{item.threadNum}}</td>
      <td>{{item.status}}</td>
    </tr>
  </tbody>
</table>

灌输
普罗西德
线程数
地位
{{item.instit}
{{item.procID}
{{item.threadNum}}
{{item.status}
以下是组件中的参考文件。

。ts:

results$: Observable<Ilivelog[]>;
ngOnInit() {
   this.result$ = this.backend.getAgentStatus().pipe(
        map(res => res.json())
   );
}
结果$:可见;
恩戈尼尼特(){
this.result$=this.backend.getAgentStatus()管道(
映射(res=>res.json())
);
}
在your view.html中

<table>
    <tr *ngFor="let log of (results$ | async)">
       <td>log.instID</td>
       <td>log.procID</td>
       <td>log.threadNum</td>
       <td>log.status</td>
    </tr>
</table>

日志输入
log.procID
log.threadNum
日志状态

首先检查JSON在验证器中是否有效。

没有帮助,我只得到了thead。我相信这不能识别这个项目。body。它说:Arrey代理:{“instit”:“2018#11#06”,“procID”:1161005,“threadNum”:0,“status”:9},{“instit”:“2018#11#06”,“procID”:1161030,“threadNum”:0,“status”:9},{“institd”:“2018#11#06”,“procID”:1161020,“threadNum”:0,“status”:9}你能帮我吗?没有显示结果。我的日志是:Arrey代理:{“instit”:“2018#11#06”,“procID”:116010,“threadNum”:0,“status”:9}我是否需要在后端使用httpClientModule或其他什么?从“@angular/Http”导入{Http};构造函数(私有http:http){}未捕获错误:模板分析错误:无法绑定到“ngForIn”,因为它不是“tr”的已知属性。(“然后它只显示:log.instit log.procID log.threadNum log.statusthe
.pipe(map(res=>res.json());
应该在
this.http.get()
之后,而不是
.subscribe()
,如果你看到getAgentStatus()返回一个可观察的值。但是如果你使用HttpClient模块,你不需要执行res.json())是的,这是主要问题,我的后端团队向我发送的是字符串而不是json。。。