I have a service which has this method:
public register(user, successCallback, errorCallback) {
const httpHeaders = new HttpHeaders({
'Content-Type' : 'application/json',
});
return this.httpClient.post(`${this.apiURL}/users/register`, user, { observe: 'response', headers: httpHeaders }).subscribe(
(response) => successCallback(response),
(error) => errorCallback(error)
);
}
I am calling that service method from a component
this.apiService.register(this.user, function(response) {
this.router.navigateByUrl('/login', { state: { registered: true } })
}, function(error) {
console.log(error);
});
On the line where I call this.router.navigateByUrl
I am getting this error:
ERROR TypeError: Cannot read property 'router' of undefined
I understand that this is not defined, but I am not sure what is the proper way of using this within a callback.
Any advice?