Fire notification toaster in any controller angularjs

前端 未结 3 1674
名媛妹妹
名媛妹妹 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:16

    i use the toastr in the following manner:

    Include toastr in your index html:

    
    

    Define a factory which you can inject in any controller:

    angular.module('app').value('ngToastr',toastr);
    
    angular.module('app').factory('ngNotifier',function(ngToastr){
        return{
            notify: function(msg){
                ngToastr.success(msg);
            },
            notifyError: function(msg){
                ngToastr.error(msg);
            },
            notifyInfo: function(msg){
                ngToastr.info(msg);
            }
        }
    });
    

    After that you can inject this module in any controller:

    angular.module('app').controller('myCtrl',function($scope, ngNotifier) {
        ngNotifier.notifyError($scope.validationError);
    });
    

提交回复
热议问题