Foxandxss / angular-toastr

Angular port of CodeSeven/toastr.
http://foxandxss.github.io/angular-toastr/
MIT License
1.3k stars 276 forks source link

Custom dynamic template #190

Open shyamal890 opened 8 years ago

shyamal890 commented 8 years ago

I would like to dynamically change the toast template. Using the following code doesn't work, renders the same template:

templates: {
                    toast: 'App/views/Toast/custom-template.html'
                }
Foxandxss commented 8 years ago

my recommendation is that you $templateCache the template before you use it.

shyamal890 commented 8 years ago

Can't this work without caching the template? I have separate logic that triggers caching process for release build. This may create a conflict.

Foxandxss commented 8 years ago

The official recommendation from angular is to provide the templates already cached. The problem here is that you won't get a valid toast the first time you use it (because the toast will be shown before the template gets fetched) and there is no way around that for this kind of widgets.

shyamal890 commented 8 years ago

@Foxandxss Check this plunker. I tried creating toast more than 2 times, custom-template is not rendered.

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

May be I am doing something wrong.

Foxandxss commented 8 years ago

Custom templates can't be changed on the toast, needs to be changed on toastrConfig.

shyamal890 commented 8 years ago

Oh, that means I can only set one template at a time. I would like to render different templates for different toasts.

Rhobal commented 8 years ago

I also tried to set a custom template, only to detect that the options "iconClasses" and "templates" are considered "bad Options" and are deleted in cleanOptionsOverride(options) Cost me >two hours to find the real problem. I am trying to set one toast with a custom template. This would mean I'll have to add a lot more ng-ifs and ng-selects to the standard template to incorporate all possibilities :-(

Please update the documentation; it now clearly says "The second option is to pass a third parameter". I have searched in vain for a hint that "templates" or "iconClasses" cannot be used for the second option. I suggest you add "(can only be used toastConfig)" to the documentation of these two options.