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

Toaster visible only on next user click #53

Closed
olaf89 opened this issue Jan 14, 2017 · 12 comments
Closed

Toaster visible only on next user click #53

olaf89 opened this issue Jan 14, 2017 · 12 comments

Comments

@olaf89
Copy link

olaf89 commented Jan 14, 2017

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.

@scttcper
Copy link
Owner

What do you mean by background stream?

@olaf89
Copy link
Author

olaf89 commented Jan 14, 2017

My actual case is rxjs stream created from websocket events, meaning no user interaction with UI.

@trevor-hackett
Copy link
Collaborator

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

@olaf89
Copy link
Author

olaf89 commented Jan 14, 2017

That was first thing i tried, and would be an acceptable solution as well. Yet it does not seem to work.

@trevor-hackett
Copy link
Collaborator

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.

@olaf89
Copy link
Author

olaf89 commented Jan 15, 2017

It works when you detect changes after onShown.
toast.onShown.first().subscribe(_ => this.appRef.tick());
Thats much better then initial solution. Thanks :)

@trevor-hackett
Copy link
Collaborator

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

@scttcper
Copy link
Owner

scttcper commented Jan 16, 2017

sounds good to me.

Maybe here? https://github.com/scttcper/toastr-ng2/blob/master/src/lib/toast-injector.ts#L35
or would putting it into the toast component itself make sense?

@trevor-hackett
Copy link
Collaborator

trevor-hackett commented Jan 16, 2017

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 ChangeDetectorRef.detectChanges() will be enough or not.

But since setting the flag to run change detection is obviously intentional, it probably isn't a bad thing to use ApplicationRef.tick().

@olaf89
Copy link
Author

olaf89 commented Jan 16, 2017

If you prepare any solution Im happy to test that, just let me know.

@scttcper
Copy link
Owner

scttcper commented Jan 17, 2017

I committed straight on master like a terrible person.

ceccaf7 has the changes. See if turning on onActivateTick works.

Released in 4.1.0

@olaf89
Copy link
Author

olaf89 commented Jan 17, 2017

I tried it and it solves the issue, thanks!

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