Fire notification toaster in any controller angularjs

前端 未结 3 1668
名媛妹妹
名媛妹妹 2020-12-14 03:53

I am using this service for notifications: https://github.com/jirikavi/AngularJS-Toaster
Is working perfectly. Already configured for that anywhere in my application I c

3条回答
  •  爱一瞬间的悲伤
    2020-12-14 04:26

    you can use angular-toaster reference it to your index.html page and also add the css, after that configure the directive at the bottom of the page as the following:

    
    

    then add it to your angular module dependencies as 'toaster' (you already did it well) so after that you'll be able to inject toaster service on any controller you want like the following:

    angular.module('myApp').controller('myController', [
        '$scope', 'toaster', function($scope,toaster) {
    
        toaster.pop('success', 'message', 'some message');
    
    }]);
    

    as the documentation says you can use a wide variety of options:

    toaster.pop('success', "title", 'Its address is https://google.com.', 15000, 'trustedHtml', 'goToLink');
    toaster.pop('success', "title", '
    • Render html
    ', 5000, 'trustedHtml'); toaster.pop('error', "title", '
    • Render html
    ', null, 'trustedHtml'); toaster.pop('wait', "title", null, null, 'template'); toaster.pop('warning', "title", "myTemplate.html", null, 'template'); toaster.pop('note', "title", "text");

    so take a look to this plunkr

提交回复
热议问题