-
Notifications
You must be signed in to change notification settings - Fork 358
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
Toaster visible only on next user click #53
Comments
What do you mean by background stream? |
My actual case is rxjs stream created from websocket events, meaning no user interaction with UI. |
You could try injecting ChangeDetectorRef into your service/component and mannually trigger a change detection using the detectChanges() method. See https://angular.io/docs/ts/latest/api/core/index/ChangeDetectorRef-class.html |
That was first thing i tried, and would be an acceptable solution as well. Yet it does not seem to work. |
Might not be working because ChangeDetectorRef.detectChanges() only triggers change detection in the local component (and it's children). Have you tried ApplicationRef.tick()? (docs) It's suppose to trigger a full change detection for the whole application if I'm understanding the docs correctly. |
It works when you detect changes after onShown. |
Might be able to do something where we add another configuration flag or something where when the toast is displayed and the flag is set, we trigger a change detection within the component. What do you think @scttcper |
sounds good to me. Maybe here? https://github.com/scttcper/toastr-ng2/blob/master/src/lib/toast-injector.ts#L35 |
Yeah that might be the best place for it. It would be nice to only trigger change detection in the components that need it. I currently don't have a setup to mimic the scenario that @olaf89 has, so I won't know if placing it withing the toast component and only triggering But since setting the flag to run change detection is obviously intentional, it probably isn't a bad thing to use |
If you prepare any solution Im happy to test that, just let me know. |
I committed straight on master like a terrible person. ceccaf7 has the changes. See if turning on onActivateTick works. Released in 4.1.0 |
I tried it and it solves the issue, thanks! |
I have an issue, when toaster is supposed to be added by background stream its not being displayed until screen is clicked.
So in order for it to become visible i need to do
setTimeout(_ => { window.document.body.click(); }, 1 );
Is there a better way to run change detection for this component? or maybe i should configure it somehow.
The text was updated successfully, but these errors were encountered: