Trying to use angular2-flash-messages and getting the console error _this.flashMessagesService.show is not a function
Followed steps per https://github.com/moff/angular2-flash-messages
app.modules.ts
import { FlashMessagesModule } from 'angular2-flash-messages';
imports: [
BrowserModule,
FormsModule,
FlashMessagesModule.forRoot(),
RouterModule.forRoot(appRoutes)
signin.component.ts has
import { FlashMessagesService } from 'angular2-flash-messages';
signin.component.ts constructor has:
constructor(
private authService: AuthService,
private router: Router,
private flashMessagesService: FlashMessagesService
) { }
onSubmit() {
this.authService.signin(this.email, this.password)
.then((res) => {
this.flashMessagesService.show('You are signed in', {
cssClass: 'alert-success', timeout: 4000
});
this.router.navigate(['/']);
})
.catch((err) => {
this.flashMessagesService.show(err.message, {
cssClass: 'alert-danger', timeout: 4000
});
this.router.navigate(['/signin']);
});
}
and get the error _this.flashMessagesService.show is not a function
// put it inside of onSubmit() method
var flashMessagesService = this.flashMessagesService;
// and call it inside your .then function
// Success
flashMessagesService.show('You are signed in', {
cssClass: 'alert-success', timeout: 4000
});
// Error
flashMessagesService.show(err.message, {
cssClass: 'alert-danger', timeout: 4000
});
Here you can check https://github.com/moff/angular2-flash-messages/issues/35
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With