I am trying to share some information between controllers with angular. I know this isn't too hard of a thing to do, I found some great examples here however I have a bit of an odd scenario with how I am bringing in and changing the data I am trying to share. I attempted to apply some other examples I had found to get this to work but could not seem to get this working so I will try to explain as clearly as I can.
The problem
What I am trying to do is pretty straight forward. I have some drop downs values I am trying to share between controllers. So whatever value it has upon landing and has been populated, and when it changes, would be shown in another controller.
The issue is that I have set up a big factory that all the controllers call from to populate their inputs, there are 10 controllers, and each has a bunch of inputs that have to be populated when landing so I have a factory with a $q.all function for each of the $http calls stored in vars, then a .then that calls another call to see if any data is saved and have the defaults changed to the saved values. I would prefer, if possible, to keep this method. I am using it everywhere and it might be a pain to change it.
So the factory looks like :
var criteria1 = $http({method: "GET", url: "/crit1"});
var criteria2 = $http({method: "GET", url: "/crit2"});
var criteria3 = $http({method: "GET", url: "/crit3"});
return {
critera: $q.all([criteria1 ,criteria2, criteria3])
}
In the controller I then do a :
getDefaults.criteria.then(function(data){
//fill out defaults and values for selects with this data
//then get saved data (if any)
$http({
method: "GET",
url: "/getsavedData/" + sectionID
})
.success(function(data, status, headers, config){
//if data !null then overrite scopes for defaults
};
So what I am trying to do is then share the value of 2 select lists on this controller with another. I was provided this example - http://jsfiddle.net/HB7LU/6510/. But I can't seem to figure out how to apply this to what I am doing. Mostly because the data is determined outside of the controller where it needs to be shared from. I am trying to avoid this, but if it is the best way then I should probably change it.
I want the inputs to populate, get defaults, then share the information with controllers (and share when it changes too). It would be ideal if I could do something similar to what 2 way data binding does, but between controllers, so the controller I am feeding to Is always feeding information of the select list answer. I've struggled with this for a bit, it should be easy, I think I am just thinking about it incorrectly. Any direction would be much appreciated. Thanks for taking the time to read!