moff / angular2-flash-messages

Angular 2 flash messages module
52 stars 21 forks source link

Explicitly triggered refresh #6

Closed coldiary closed 7 years ago

coldiary commented 7 years ago

Hi !

I was experiencing some inconsistent refreshes upon adding multiple flash messages simultaneously with the show method. View did not refresh as supposed to.

So here is a little fix, if you approve it :

Explicitly trigger refresh of the component view using ChangeDetectorRef

  1. Added import of ChangeDetectorRef from '@angular/core'
  2. Added injection of ChangeDectectorRef as private _cdRef
  3. Called detectChanges() on _cdRef private member after insertion and removal of a message in order to explicitly refresh the view.

Note: I'm choosing ChangeDetectorRef rather than zone.run() in order to detect component and children changes, and not traversing the entire tree. But if changes were about to happen outside the module, the second solution would be preferable.

moff commented 7 years ago

@coldiary Sorry for the delay! I'm traveling at the moment. Thank you for your efforts!

coldiary commented 7 years ago

No problem. I actually thought it was pretty fast, since I didn't contribute to any project before. It came quick, in my opinion. Glad you found it useful !

Le 3 déc. 2016 à 11:24, Paul Moff notifications@github.com a écrit :

@coldiary Sorry for the delay! I'm traveling at the moment. Thank you for your efforts!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.