【发布时间】:2018-07-15 12:51:34
【问题描述】:
当我尝试在标准 html 表中显示数组数据时遇到问题。有一种方法是 soa.service 可以获取数组中的数据。
服务。
get(Type: number, Code: string): Observable<Items[]> {
var requestOptions = this.authService.requestOptionsWithToken();
return this.http.get(this.serviceUrl + 'api/Get/' + Type + '/' + Code, requestOptions)
.map(this.dataService.extractData)
.catch(this.dataService.handleError);
}
public extractData(res: any) {
return res.json() || [];
}
component.ts
chaptersItems: Items[] = [];
soaType: number;
soaCode: string = 'en-us';
ngOnInit() {
this.onGet(this.Type, this.Code);
}
onGet(Type: number, Code: string) {
this.service.get(Type, Code)
.subscribe(
response => {
this.chaptersItems = response;
console.log(this.chaptersItems);
});
chapter.component.html
<table>
<tr *ngFor="let item of chaptersItems">
<td>{{item.name}}</td>
<td>{{item.description}}</td>
</tr>
</table>
【问题讨论】:
标签: angular typescript