简体   繁体   English

使用john papas库toastr for angularjs有什么好处?

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

Toastr Repo I'm studying best practices of angular. Toastr Repo我正在研究角度的最佳实践。 In the repo john papa / ng-demos john papa included a library he wrote called toastr. 在回购书中,约翰·帕帕( John papa)/ ng-demos约翰·帕帕(John papa)包括了他写的一个名为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 //logger.js服务

(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. Toastr是一个ui库,可让您轻松向最终用户显示通知。 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. 很好,因为用法非常简单,并且允许您在不阻止ui的情况下进行通知,它有缺点,需要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 典型情况是在服务器上执行异步操作时,服务器过了一会儿确认请求的操作正确执行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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