我正在尝试从oracle获取数据并显示它。我使用express和节点创建了一个服务,并且能够成功地运行它。我已经创建了角服务来获取数据,并将其赋值于角分量,但是我无法将JSON响应映射到角变量。请检查下面的代码,并帮助我在角度component.ts中需要更改什么,以及如何在html中使用该变量。
来自oracle DB的JSON数据:
[{"COUNT":27}]
角度服务:
getCount(): Promise<String[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => response.json().data)
.catch(this.handleError);
}
角component.ts
dataGS : String[];
getData(): void {
this.dataService
.getCount()
.then(dataGS => this.dataGS = dataGS);
发布于 2017-10-12 23:53:12
您的响应没有属性data
,它只是一个数组。因此,与其:
.then(response => response.json().data)
做:
.then(response => response.json())
现在你将得到你的数组。然后,按照jitender的建议,您可以迭代您的响应:
<div><p *ngFor="let d of dataGS ">{{d}}</p></div>
发布于 2017-10-12 19:57:15
关于
getCount(): Promise<String[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => {
response.json().map(function(item) {
return item['COUNT'];
})
})
.catch(this.handleError);
}
在html中
<div><p *ngFor="let d of dataGS ">{{d}}</p></div>
https://stackoverflow.com/questions/46722178
复制