Unreachable code detected non-angular

1

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.

    
asked by anonymous 01.08.2018 / 14:25

1 answer

2

As you yourself said it does not make the notifty as it is after a return. To resolve, where you call the checkOrder method you can call notify inside the subscribe.

this.service.checkOrder(parametroquevocepassou)
.subscribe(res => {
   this.notificationService.notify('cadastro feito com sucesso')  
})
    
01.08.2018 / 14:37