I am facing an issue while attempting to display array data in a standard HTML table. There is a method called soa.service that retrieves data in an array format.
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>