[英]Using toastr in the AngularJS way
Currently, I just call toastr.success('my message')
within a controller where required. 目前,我只需要在控制器内调用
toastr.success('my message')
。 This work fine, but it feels a bit dirty to me. 这工作很好,但对我来说感觉有点脏。
Is there a 'best practice' or recommended 'angularjs' way of using the toastr.js library ? 是否有使用toastr.js库的“最佳实践”或推荐的“angularjs”方式?
Yes. 是。 Pretty simply:
非常简单:
app.factory('notificationFactory', function () {
return {
success: function (text) {
toastr.success(text,"Success");
},
error: function (text) {
toastr.error(text, "Error");
}
};
});
Resolve factory in controller. 解决控制器中的工厂问题。 Customize messages, notifications/etc in factory.
在工厂中自定义消息,通知/等。
Despite the idea that code adds another abstraction, it's really effective. 尽管代码添加了另一个抽象概念,但它确实很有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.