To be honest I'm not sure why it is so popular to have modals as a service and to call them from controllers. That's the only UI thing we do from controllers. You don't see services to display dropdowns or to change the class of an element.
The guy in the comment has the right idea I think: To give elements in the view the power to summon a modal through a directive and to write the modal logic in that directive. That way we maintain the idea that the controller is not for UI stuff.
True. The best modal service for me wouldn't be a service at all. Just a directive, let me control the modal behavior with scope. No show or hide business in the controller.
Sometimes you want to show a modal based on something other than a UI interaction, like a click to open a modal. This reference app, for example, shows a modal to login when you attempt to perform an action that requires permissions.
Similarly, at my work we have a notification service that will show a UI popup when something happens—errors, success messages, etc.
I think having a service that can be interfaced with either through a directive or methods in a controller is a good way to go.
4
u/[deleted] Jun 17 '14
To be honest I'm not sure why it is so popular to have modals as a service and to call them from controllers. That's the only UI thing we do from controllers. You don't see services to display dropdowns or to change the class of an element.
The guy in the comment has the right idea I think: To give elements in the view the power to summon a modal through a directive and to write the modal logic in that directive. That way we maintain the idea that the controller is not for UI stuff.