Hello,
Scenario:
- Main Controller fetches data from webservice upon initialization
- nested controller must do something on that data upon its own initialization
I wonder what is the best way of solving that issue?
Here is example of the problem. It fails because data is not available while nested controller is being initialized. Example is very primitive, what's important is that some data is fetched from webservice and assigned to scope. Then nested controller expectes that data but there's nothing and everything fails.
and here is the solution to this problem using $q service
I tried to use resolve on route but I could not inject $scope so I gave up and tried promises as shown above.
Questions:
1. Is there a better way of doing that?
2. Generally, how initialization should be done? So far I've been writing some code inside controller, followed by methods assigned to scope and I'm not happy with that. It lacks structure.
Kind regards,
Marek