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

Dismiss programatically #56

Closed
red010182 opened this issue Mar 6, 2015 · 2 comments
Closed

Dismiss programatically #56

red010182 opened this issue Mar 6, 2015 · 2 comments

Comments

@red010182
Copy link

I want to use this toast to show loading indicator (especially in http request). However, I would never know how long a http request would take so I cannot use timeout parameter to control the toast. I want to fire a loading toast before http request and close it in response callback without a user interaction.

Any way to do that?

@Foxandxss
Copy link
Owner

Sure, you can do something like (writing from memory):

var toast = toastr.info('Loading stuff', {
  timeOut: 0,
  extendedTimeOut: 0
});
$http.get('/my/endpoint').then(function(result) {
  toastr.clear(toast);
  return result;
});

Basically, you fire a permanent toast and then when your $http request resolves, you close the toast. It is really important that you return result from it, so when you chain the promise in your controller, it will receive those results.

@red010182
Copy link
Author

Thank you, works perfect.

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

2 participants