Javascript 在Toastr.js中注入/使用Angular服务
我最近开始使用Toastr.js库在angular网站上显示警报。我使用Angular服务连接到数据库并拉取或发布警报,然后将生成的警报发送到toastr服务,该服务工作正常。我想自定义库,这样当用户单击toast上的close图标时,toastr服务将向数据库发送更新。我在定制的toastr.js中有相关的代码,但我不知道如何使用预先存在的Angular服务进行此调用 如何将预先存在的Angular服务注入/引用/使用到toastr.js中,以便使用其方法发布到数据库?它不使用Angular,而是使用require语法包装 作为参考,toastr.js如下所示: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,
(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>×</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>×</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
});