Controller running Parse query before scope variable resolved

110 views Asked by At

I currently have a dashboard that has a variable x that is needed throughout my application. I have a factory in my dashboard.js that listens for x's value to change and updates it if needed. dashboard.js runs first and resolves x. There are several pages that have their own controllers that load after dashboard.js. These pages listen/use variable x. I am currently running Parse queries in the controllers of these pages however x is showing up as undefined so I cannot use it in my query. How do I run a controller only after x is defined?

1

There are 1 answers

0
skubski On

Assuming the relationship between your controllers already is a parent-child relationship and your variable is declared on the $scope, your childcontrollers should normally inherit that variable. Without any code , its hard to tell.

Either way, you could use the $rootScope to make that variable accessible. Eventhough this is technically possible , this is generally not the way you want to do it.

Then you have to possibility to broadcast/emit and watch and event as X changes. You can also transmit data over an event. This is what you are already doing, I guess?

You could also create a service that is injected in every controller, regardless of their relation, that keeps track of your variable. Or in your case, you could assign that functionality to the factory too.

But it is hard to tell without any code what you're trying to do.