Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

angular 2 flash messages show multiple times #41

Open
ds-manish opened this issue May 18, 2018 · 3 comments
Open

angular 2 flash messages show multiple times #41

ds-manish opened this issue May 18, 2018 · 3 comments

Comments

@ds-manish
Copy link

ds-manish commented May 18, 2018

Hi, the flash messages show multiple times, is there any way to display the latest flash message only.
The flash message gets piled up.

2018-05-18 03 37 46 pm

@SanchitSahu
Copy link

Did you find a solution for this? I am having the same issue

@moff
Copy link
Owner

moff commented Aug 23, 2018

@SanchitSahu, @ds-manish Do you call .show() method multiple times? By default, flash message is visible for 2.5 seconds.

@ghost
Copy link

ghost commented Sep 17, 2018

@ds-manish I actually had to look in the source code to refactor an array called messages in the flash-messages.component.js file. What's happening with that array is that it simply pushes each error message that is received, but they don't go away, because of the window timeout function that removes them after 2.5seconds as @moff already mentioned.
So what I did there is that I checked if the "options" array hasOwnProperty('timeout'). Whether or not it has that property is determined by the .show(msg, options) methods options object. That means you can either set a timeout or not. So basically window.setTimeout function is set only if you passed a timeout property to the options object. Okay, so this gives you more control over the defaults object. Moving on.
Next up is the messages array. What you should do there is simply assign the messages array to an empty array, then you push the new message. And now only the latest message will be shown. This worked for me, hope it works for you too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants