Look at this snippet of code;
this.notificationService.notify('cadastro feito com sucesso')
I created a project in Angular, it is an ecommerce system, every time I select a product it can notify the message on screen perfectly using that code snippet just above, but when I use this snippet of code in an observable method it gives problem.
In this code it works quietly;
removeItem(item: CartItem) {
this.items.splice(this.items.indexOf(item), 1)
this.notificationService.notify('Você removeu um item ${item.menuItem.name}');
}
But in this code below does not work;
checkOrder(order: Order): Observable <string> {
const headers = new Headers()
headers.append('Content-Type', 'application/json')
return this.http.post('${this.url}/orders',
JSON.stringify(order),
new RequestOptions({ headers: headers }))
.map(response => response.json())
this.notificationService.notify('cadastro feito com sucesso')
}
It gives this error message = > order.service.ts (55,10): Unreachable code detected.
The error I took is because it has a line of code after a return.
To notify in a successful response, simply call in the subscribe of Observable or use the operator of the. For example, but I do not know how to modify my code to work despite knowing in theory how to solve.
I need help.