July 2018
Intermediate to advanced
420 pages
8h 46m
English
Let's create the Register function. After the constructor function, let's add the following code:
onRegister(user: User): Observable<User> {
const request = JSON.stringify(
{ name: user.name, email: user.email, password: user.password }
);
return this.http.post(this.registerUrl, request, httpOptions)
.pipe(
map((response: User) => {
// Receive jwt token in the response
const token: string = response['access_token'];
// If we have a token, proceed
if (token) {
this.setToken(token);
this.getUser().subscribe();
}
return response;
}),
catchError(error => this.handleError(error))
);
}
Note that we are using the pipe(), map(), and catchError() functions from the Reactive Extensions Library for JavaScript (RxJS) that's ...
Read now
Unlock full access