3

Have been trying to use toastr in my AngularJS app:

app.module("MyApp", ['toastr']);

But it doesn't work, the module toastr can not be found! I thought toastr were a AngularJS module?

Anyone who knows how to load the module, or if there are any Angular-directives I can use?

2
  • Are you sure that the module is loaded? <script type="text/javascript" src="angular-toastr.tpls.js"></script> Commented Apr 15, 2015 at 11:33
  • What's the instantiation of app look like? It's hard to tell from the lack of code how you're instantiating app. Commented Apr 15, 2015 at 11:47

4 Answers 4

5

Without seeing the instantiation of app, in your example, there's no way for me to know if you're actually loading your dependencies correctly; so I'll take you through the steps to load it from scratch (Source: here).

There are a few things you have to do to get toastr working on AngularJS:

  1. Download the angular-toastr distribution.
  2. add the following to your index.html (effectively wherever you're loading all your scripts):

<link rel="stylesheet" type="text/css" href="angular-toastr.css" /> <script type="text/javascript" src="angular-toastr.tpls.js"></script>

  1. Add toastr to the app's modules (not each controller, or a service. Add it to the app). Your app.js file:

angular.module('myApp', ['toastr']).

Sign up to request clarification or add additional context in comments.

2 Comments

I've tried exactly what you've written above, but am still having no luck. Still getting an injector error, see screenshot: dropbox.com/s/karwq1v9e498i7v/… Any idea why?
ha, it might have had something to do with my using toastr.js and not angular.toastr.js. Whoops!
2

No, toastr is not an Angular module. There are various ports of toastr to Angular including angular-toastr or AngularJS-Toaster.

Comments

1

You don't need to inject it as a dependency unless you are using angular port of toastr (eg: angular-toastr). For the original toastr, just including the .js and .css, and should be fine.

Comments

0

You don't have to add toastr as a dependency in your module. You just need to include toastr.js and toastr.css files in your project and you can then toastr like this

toastr.success("This is a success message");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.