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

Used in a service, toastr.clear() not working #137

Open
OpenNoob opened this issue Nov 8, 2015 · 11 comments
Open

Used in a service, toastr.clear() not working #137

OpenNoob opened this issue Nov 8, 2015 · 11 comments

Comments

@OpenNoob
Copy link

OpenNoob commented Nov 8, 2015

Hi,

As in the title, calling the clear method doesn't work when toastr is used in service/factory. Calling them to show works, no problem.

How exactly can this be used in a service?

Thanks

@Foxandxss
Copy link
Owner

It shouldn't give you any problem at all. In Angular, services (like toastr) is a singleton, so no matter where you call it, it will always have the same data.

@ZuSe
Copy link

ZuSe commented Mar 7, 2016

@OpenNoob

Have you found a solution for this issue? I am running in exactly the same problem.

@Foxandxss
Copy link
Owner

I would love some reproduction.

@ZuSe
Copy link

ZuSe commented Mar 7, 2016

Add an empty array and it wont work. Leave out the array and it works.
Add one toast to the array given as input to the service.function and it does not work.
I have like

myCtrl.function = function(){
...
let myToast = toast.info(....)
FileManager.uploadFile(fileToUpload, myToast);

}

FileManager.uploadFile = function(fileToUpload, mytoast){
Upload.uploadFile(fileToUpload).then(
toastr.clear([mytoast]) // does not work
}

@Foxandxss
Copy link
Owner

clear accepts a toast, not an array of toasts. An array of toasts could be a nice addition tho.

@haffmaestro
Copy link

haffmaestro commented Jun 14, 2016

@Foxandxss your example here makes it look a lot like the toast is supposed to be in an array. I'm also having trouble with this and cannot get it to work, are there specific toastrConfig settings that need to be set in order for clear to work?

@Foxandxss
Copy link
Owner

And you are totally right. That syntax is used when you have an optional parameter, say foo(arg1, [arg2]) but could mean an array as well.

You shouldn't need to do something special to clear toasts. What are you trying?

@haffmaestro
Copy link

haffmaestro commented Jun 14, 2016

@Foxandxss, thanks for fast response!
Basically I have a wrapper of toastr that does the following,

function show(msg, opts = {}) {

    var notification = toastr.info(msg, opts);
    notification.removeSelf = () => toastr.clear(notification);

    return notification;
  }

And when I do notification.removeSelf() nothing happens.

@Robinson7D
Copy link

removeSelf with clear appears to work as expected in plunkr, I expect it may be something related to the rest of (our) codebase or dependencies:

http://plnkr.co/edit/BLi5KUU0yEJU4wrT6sDv?p=preview

@Amenel
Copy link

Amenel commented Sep 23, 2016

In reaction to this comment, I believe that it should be made clearer in the documentation that this is not an array notation, but rather an optional parameter notation. I fell into that trap too although once the "optional parameter" explanation comes in, it feels like a "dumb me, I know that!!!" moment.

@ahgittin
Copy link

I encountered this also. Seems $destroy doesn't always cause the element to be removed immediately. I think I've fixed this in #219 (at least in my case). Also added support for [toast1, toast2] to accommodate the ambiguous instructions.

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

7 participants