Closed Adlesa closed 6 years ago
@Adlesa that's because inside of .then
you use anonymous function, therefore when you call this.something
inside its body you actually make a call to the function context - not a class.
You should use something like:
// put it inside of onSubmit() method
var flashMessagesService = this.flashMessagesService;
// and call it inside your .then function
flashMessagesService.show('Kunden er nu oprettet', { cssClass: 'alert alert-success', timeout: 2000 });
@moff You are completely right.
Thank you very much - it works perfectly now.
I am having the same problem, but your solution is not working for me.
this.currentUser.updatePassword(this.pF.passwordOne.value) .then(() => { this.flashMessages.show('Password Updated.', { cssClass: 'alert-success', timeout: 2000 }); })
Producing the error: ERROR TypeError: Cannot read property 'flashMessages' of undefined
Do you have any other solutions or thoughts on the issue? It's been imported, and instantiated in the constructor as instructed. What's very odd is that it works in a different place with the same code...
Any help much appreciated.
I cant get my head around this problem.
This is the Code:
If I move the:
this.flashMessagesService.show('Kunden er nu oprettet', { cssClass: 'alert alert-success', timeout: 2000 });
outside the .then block it runs fine but inside the .then I get this error: Error writing document: TypeError: Cannot read property 'flashMessagesService' of undefinedAny suggestions?