【发布时间】:2018-10-25 12:31:15
【问题描述】:
我有这个 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支持绑定到可迭代对象,例如数组。
【问题讨论】:
-
您的环境阵列在哪里?您需要先执行以下操作:`getEnviroments() { this.enviroments = this._http.get(this.baseUrl + "/environments", this.options); }`
-
@user9793665 你的环境是数组类型吗?例如。
[{name:'name 1'}, {name:'name 2'}] -
@user9793665 只需将环境数组绑定到订阅结果。
this.environments = containers
标签: javascript angular