I am attempting to utilize this code to post data from a web service.
service.ts
public events(id: string): Observable<Events> {
......
return this.http.post(Api.getUrl(Api.URLS.events), body, {
headers: headers
})
.map((response: Response) => {
let res = response.json();
if (res.StatusCode === 0) {
return res.StatusDescription;
} else {
return new Events(null);
}
});
}
This code displays all my data. If the web service does not receive any data, no results are shown and this function throws an error:
ERROR Error: Cannot find a differ supporting object 'No result' of type 'string'. NgFor only supports binding to Iterables such as Arrays.
To display on the page, I used the following code:
event: Events;
events: Events[]=[];
getalleventsserial() {
this.activatedRoute.params.subscribe(
params => {
this.ns.events(params['id']).subscribe(
events => {
this.event = events;
}
);
}
);
}
html code:
<table *ngFor="let item of event">
<tr>
<td>{{item.id}}</td>
<td>{{item.alarmnr}}</td>
<td>{{item.name}}</td>
</tr>
</table>
Please, could you provide a solution for this issue? Thank you