Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
75
rated 0 times [  80] [ 5]  / answers: 1 / hits: 23605  / 11 Years ago, tue, february 4, 2014, 12:00:00

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?


More From » angularjs

 Answers
11

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.


[#72718] Monday, February 3, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irvingcarloe

Total Points: 677
Total Questions: 109
Total Answers: 96

Location: Svalbard and Jan Mayen
Member since Sun, Sep 25, 2022
2 Years ago
irvingcarloe questions
Wed, Mar 31, 21, 00:00, 3 Years ago
Tue, Aug 4, 20, 00:00, 4 Years ago
Fri, Jul 3, 20, 00:00, 4 Years ago
;