Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Toastr.js中注入/使用Angular服务_Javascript_Angularjs_Dependency Injection_Toastr - Fatal编程技术网

Javascript 在Toastr.js中注入/使用Angular服务

Javascript 在Toastr.js中注入/使用Angular服务,javascript,angularjs,dependency-injection,toastr,Javascript,Angularjs,Dependency Injection,Toastr,我最近开始使用Toastr.js库在angular网站上显示警报。我使用Angular服务连接到数据库并拉取或发布警报,然后将生成的警报发送到toastr服务,该服务工作正常。我想自定义库,这样当用户单击toast上的close图标时,toastr服务将向数据库发送更新。我在定制的toastr.js中有相关的代码,但我不知道如何使用预先存在的Angular服务进行此调用 如何将预先存在的Angular服务注入/引用/使用到toastr.js中,以便使用其方法发布到数据库?它不使用Angular,

我最近开始使用Toastr.js库在angular网站上显示警报。我使用Angular服务连接到数据库并拉取或发布警报,然后将生成的警报发送到toastr服务,该服务工作正常。我想自定义库,这样当用户单击toast上的close图标时,toastr服务将向数据库发送更新。我在定制的toastr.js中有相关的代码,但我不知道如何使用预先存在的Angular服务进行此调用

如何将预先存在的Angular服务注入/引用/使用到toastr.js中,以便使用其方法发布到数据库?它不使用Angular,而是使用require语法包装

作为参考,toastr.js如下所示:

(function (define) {
    define(['jquery'], function ($) {
        return (function () {
            //code stuff here, functions
        });
}(typeof define === 'function' && define.amd ? define : function (deps, factory) {
    if (typeof module !== 'undefined' && module.exports) { //Node
        module.exports = factory(require('jquery'));
    } else {
        window.toastr = factory(window.jQuery);
    }
}));
使用插件

下面是如何编辑toastr的配置和自定义

app.config(function(toastrConfig) {
  angular.extend(toastrConfig, {
    allowHtml: false,
    closeButton: false,
    closeHtml: '<button>&times;</button>',
    extendedTimeOut: 1000,
    iconClasses: {
      error: 'toast-error',
      info: 'toast-info',
      success: 'toast-success',
      warning: 'toast-warning'
    },  
    messageClass: 'toast-message',
    onHidden: null,
    onShown: null,
    onTap: null,
    progressBar: false,
    tapToDismiss: true,
    templates: {
      toast: 'directives/toast/toast.html',
      progressbar: 'directives/progressbar/progressbar.html'
    },
    timeOut: 5000,
    titleClass: 'toast-title',
    toastClass: 'toast'
  });
});
app.config(函数(toastrConfig){
角度。延伸(到strconfig{
allowHtml:false,
closeButton:false,
closeHtml:“×;”,
延长超时时间:1000,
i包括:{
错误:“toast错误”,
信息:'吐司信息',
成功:为成功干杯,
警告:“敬酒警告”
},  
messageClass:“toast消息”,
onHidden:null,
onShown:null,
onTap:null,
progressBar:错,
塔普托迪斯:没错,
模板:{
toast:'directions/toast/toast.html',
progressbar:“指令/progressbar/progressbar.html”
},
超时:5000,
标题类:“祝酒词标题”,
烤面包课:“烤面包”
});
});
带有自定义HTML的Toast
toastr.info('Success!','With HTML'{
allowHtml:是的
});
使用插件

下面是如何编辑toastr的配置和自定义

app.config(function(toastrConfig) {
  angular.extend(toastrConfig, {
    allowHtml: false,
    closeButton: false,
    closeHtml: '<button>&times;</button>',
    extendedTimeOut: 1000,
    iconClasses: {
      error: 'toast-error',
      info: 'toast-info',
      success: 'toast-success',
      warning: 'toast-warning'
    },  
    messageClass: 'toast-message',
    onHidden: null,
    onShown: null,
    onTap: null,
    progressBar: false,
    tapToDismiss: true,
    templates: {
      toast: 'directives/toast/toast.html',
      progressbar: 'directives/progressbar/progressbar.html'
    },
    timeOut: 5000,
    titleClass: 'toast-title',
    toastClass: 'toast'
  });
});
app.config(函数(toastrConfig){
角度。延伸(到strconfig{
allowHtml:false,
closeButton:false,
closeHtml:“×;”,
延长超时时间:1000,
i包括:{
错误:“toast错误”,
信息:'吐司信息',
成功:为成功干杯,
警告:“敬酒警告”
},  
messageClass:“toast消息”,
onHidden:null,
onShown:null,
onTap:null,
progressBar:错,
塔普托迪斯:没错,
模板:{
toast:'directions/toast/toast.html',
progressbar:“指令/progressbar/progressbar.html”
},
超时:5000,
标题类:“祝酒词标题”,
烤面包课:“烤面包”
});
});
带有自定义HTML的Toast
toastr.info('Success!','With HTML'{
allowHtml:是的
});

检查下面有代码段的答案检查下面有代码段的答案
toastr.info('<input type="checkbox" checked> Success!', 'With HTML', {
  allowHtml: true
});