I am trying to display all of my notifications in HTML.
The value is returned in res = response.json();
, but my website only shows one notification, similar to the example in https://i.sstatic.net/ECbyx.png
Let's start with this code:
public eventsbyserial(id: string): Observable<Notifications> {
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('serial_device', id);
urlSearchParams.append('token', this.auth.getCurrentUser().token);
let body = urlSearchParams.toString();
return this.http.post(Api.getUrl(Api.URLS.eventsbyserial), body, {
headers: headers
})
.map((response: Response) => {
let res = response.json();
console.log(res) // this shows me all notifications
if (res.StatusCode === 0) {
return new Notifications(res.StatusDescription[0]);
} else if (res.StatusCode === 1) {
this.auth.logout();
} else {
return new Notifications(null);
}
});
}
Next, we have this code snippet:
notificcationserial: Notifications[]=[];
notif: Notifications;
getalleventsserial() {
this.activatedRoute.params.subscribe(
params => {
this.ns.eventsbyserial(params['id']).subscribe(
notificcationserial => {
this.notif = notificcationserial;
console.log(this.notif) // Only one notification is displayed here
}
);
}
);
}
In the HTML:
<table *ngFor="let item of notificcationserial ">
<tr >
<td> {{item.alarmnumber}}</td>
<td> {{item.acted}}</td>
</tr>
</table>
I'm facing an issue where only one notification is being displayed on my site. Any ideas for a solution?
UPDATE:
if (res.StatusCode === 0) {
return new Notifications(res.StatusDescription);
The result shows as undefined, similar to the image shown here: https://i.sstatic.net/ED17l.png