Incorporating toastr in to your application the ‘Angular’ way

toastr is a great little javascript library for generating notifications or ‘toasts’ for your users. To use it, you simply include the javascript file and the associated css in to your project and then call one of the various methods on the events on which you wish to display a notification.

However, a little bit of work is required if you want to use this library in an AngularJS application following the best practice of not manipulating the DOM directly via your controller. You should wrap the calls to the toastr library in an angular service as follows:

app.factory('notificationFactory', function () {
    return {
        success: function () {
        error: function (text) {
            toastr.error(text, "Error");