Hi,
I know that the communication between controllers has been discussed some times. And one solution was to use a common parent controller which stores the common data, or use a service to keep the shared state.
In the jquery-mobile-angular-adapter we created another solution: a shared controller. This is a controller which gets an own scope, and is injected into the current scope using a variable as prefix.
Syntax: <ANY ngm-shared-controller="name1:Controller1,name2:Controller2, ...">
Access to those controller in the page: {{name1.ANY}}, ...
Reasons behind this:
a) In mobile projects, business logic for one use case is very often spread across multiple mobile pages. Creating an own controller for every page would be a lot technical code, and we would need to pass a lot data between those simple page controllers.
b) Using a common parent controller is also no good solution for projects with jquery mobile:
Every page is at the same dom element depth, usually directly under the "body"-tag. So we can only create on common parent controller for all pages. However, this would put different aspects of the application in a single file, which is not good from a maintenance point of view.
c) Using a service to hold the common data is also not working well, as we then still need a controller for every page, right?
I posted this to share this code with you and to get some feedback from the community about this, so:
What do you think about this solution for the problem mentioned above?
Tobias