Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
目前,我只是toastr.success('my message')在需要时在控制器内调用。这工作很好,但对我来说感觉有点脏。
toastr.success('my message')
是否有使用toastr.js 库的“最佳实践”或推荐的“angularjs”方式?
是的。很简单:
app.factory('notificationFactory', function () { return { success: function (text) { toastr.success(text,"Success"); }, error: function (text) { toastr.error(text, "Error"); } }; });
解析控制器中的工厂。在工厂自定义消息、通知/等。
尽管代码添加了另一个抽象的想法,但它确实有效。