Question - based on the Angular doc, when is it more appropriate to use next vs complete for my observable?
I'm looking through someones Angular 7 project and I see a lot of code that looks like this below where some calls use next and some just use complete and I'm trying to know when to use the appropriate one based on the Angular doc, because next is 'required' and complete is 'optional'.
login() {
this.authService.login(this.model).subscribe(next => {
this.alertService.success('Logged in successfully');
}, error => {
this.alertService.danger(error);
}, () => {
this.router.navigate(['/home']);
});
}
register() {
this.authService.register(this.user).subscribe(() => {
this.showRegistrationComplete = true;
}, error => {
// handle the error code here
}
);
}
Where in some cases I see 'next' and some cases I see '()' complete for the subscribe.
Both of these 2 calls above call these below (post methods to a controller)
login(model: any) {
return this.http.post(this.baseUrl + 'login', model).pipe(
map((response: any) => {
const user = response;
if (user) {
// do some stuff
}
})
);
}
register(model: any) {
return this.http.post(this.baseUrl + 'register', model);
}
What happens if I have this below - does this mean 'complete' or does this mean 'next' because it's the first parameter in the subscribe?
this.authService.login(this.model).subscribe(() => {
this.alertService.success('Logged in successfully');
this.router.navigate(['/home']);
}, error => {
this.alertService.danger(error);
});