Currently, I just call toastr.success('my message')
within a controller where required. 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 ?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.