Angular打印html中的简单文本

时间:2018-05-15 15:36:52

标签: javascript angular

我有这个json

[
  {
    "id": 3,
    "name": "Test",
    "activityDays": 2,
    "coreBankingBranch": "master",
    "csrBranch": "master",
    "adminBranch": "master",
    "clientBranch": null,
    "creationDate": null,
    "serverName": "ATP",
    "cloneTag": null,
    "csrIsCompleted": false,
    "adminIsCompleted": false,
    "clientIsCompleted": false,
    "completed": false
  }
]

我来自:

组件

 this.docker.getContainers().subscribe(containers => {
  console.log(containers);
});

服务

 getEnvironments() {
return this._http.get(this.baseUrl + "/environments", this.options);
}

我尝试使用

进行打印
<tr *ngFor="let environment of environments">
      <td>{{ environment.name }}</td>
    </tr>

但我得到

EnvironmentComponent.html:79 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only
     

支持绑定到诸如Arrays之类的Iterables。

1 个答案:

答案 0 :(得分:0)

似乎您没有将environments与响应绑定。还必须启动组件中的environments

this.docker.getContainers().subscribe(containers => {
  this.environments = containers  // assuming container is the shared response 
});