Installing toastr in an AngularJS app

Andreas Selenwall picture Andreas Selenwall · Apr 15, 2015 · Viewed 7.2k times · Source

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?

Answer

George Stocker picture George Stocker · Apr 15, 2015

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']).