简体   繁体   中英

What are the benefits of using john papas library toastr for angularjs?

Toastr Repo I'm studying best practices of angular. In the repo john papa / ng-demos john papa included a library he wrote called toastr.

Question: I do not understand, What would the benefit of toastr? Why should I use toastr? What would be a common typical usecase?

//logger.js Service

(function() {
    'use strict';

    angular
        .module('blocks.logger')
        .factory('logger', logger);

    logger.$inject = ['$log', 'toastr'];

    function logger($log, toastr) {
        var service = {
            showToasts: true,

            error   : error,
            info    : info,
            success : success,
            warning : warning,

            // straight to console; bypass toastr
            log     : $log.log
        };

        return service;
        /////////////////////

        function error(message, data, title) {
            toastr.error(message, title);
            $log.error('Error: ' + message, data);
        }

        function info(message, data, title) {
            toastr.info(message, title);
            $log.info('Info: ' + message, data);
        }

        function success(message, data, title) {
            toastr.success(message, title);
            $log.info('Success: ' + message, data);
        }

        function warning(message, data, title) {
            toastr.warning(message, title);
            $log.warn('Warning: ' + message, data);
        }
    }
}());

Toastr is a ui library that allows you to easily show notifications to the end user. it is nice because is usage is very simple and allow you to do notifications without blocking ui it has a draw back it requires jquery.

Typical scenario is when you perform and async operation on the server and after a while the server confirms the correct execution of the requested operation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM