0

I have this code:

this.userService.register(value).pipe(
    finalize(() => this.isRequesting = false)
).subscribe(
    () => this.router.navigate(['/login'], { queryParams: { brandNew: true, email: value.email } }),
    (error: any) => this.errors = error
);

It doesn't work until I put a semicolon before this.router:

() => ; this.router.navigate(['/login'], { queryParams: { brandNew: true, email: value.email } }),

It is really weird, why should this be happening? It has nothing to do with this.router.navigate because if I replace it by an alert like this alert('alert') it doesn't work again until I put a semi-colon before it. It seems really odd to me, would you please help me with this?

Also the error that it throws is just a simple [object Object] which makes me more confused, I have also looked at this question but changing the browser to chrome had no effect: Resolver Emitting Error ` ERROR Error: "[object Object]" `

This is the register method of the userservice:

register(userRegistration: UserRegistration): Observable<{}> {

  let headers = new HttpHeaders({ 'Content-Type': 'application/json' });

  return this.http.post(this.baseUrl + "/account", userRegistration, { headers: headers });
}
  • Can you provide minimal reproduction on stackblitz. The current code seems to be right. – Sachin Gupta Apr 11 '19 at 07:47
  • @SachinGupta No. It doesn't right, I have tested it in different ways, it really doesn't work for me until I put a semi-colon before that line! –  Apr 11 '19 at 07:48
  • You've likely got a bug somewhere higher up. – Liam Apr 11 '19 at 07:51
  • Please provide a stackblitz and we can learn more about it. – Sachin Gupta Apr 11 '19 at 07:51
  • @Liam If so, why the bug somewhere higher up, should be disappeared by putting the semi-colon here? –  Apr 11 '19 at 07:52
  • Because the semi colon will end the line. Everyone else is right, we need a [MCVE here to help](https://stackoverflow.com/help/mcve) without this we're guessing. This is why [you should put semi colons on every line](https://stackoverflow.com/questions/444080/do-you-recommend-using-semicolons-after-every-statement-in-javascript) – Liam Apr 11 '19 at 07:53

0 Answers0