Next, we need to go through our components and replace console logged messages with our alertify errors.
In all of these components, first inject the alertify service into the constructor.
constructor(private _alertify: AlertifyService) { }
login() {
this.authService.login(this.model).subscribe(data => {
this._alertify.success('Logged in successfully'); // <--- changed
}, error => {
this._alertify.error('Failed to login.'); // <--- changed
}, () => {
this.router.navigate(['members']);
});
}
logout() {
this.authService.userToken = null;
localStorage.removeItem('token');
this._alertify.success('Logged out'); // <--- changed
this.router.navigate(['/home']);
}
register() {
this._authService.register(this.model).subscribe(() => {
this._alertifyService.success('Registration successful'); // <--- changed
}, error => {
this._alertifyService.error(error); // <--- changed
});
}
Testing Alertify Messages
Open the browser and verify that the alertify messages are displaying correctly.