So, I wanted to make 2 HTTP calls in order to get some groups and questions from my server, and both of these problems were resolved in the router so that the corresponding controller would not load before I had the appropriate data.
In my other controllers, I always worked with an initalData object to store data.
Part of permission:
resolve: { initialData: ["GroupsService" "QuestionsService", function (GroupsService, QuestionsService) { return { questions: QuestionsService.getAll(), groups: GroupsService.getAll() }] }
When I tried to access the data in the controller using initialData.questions and initialData.groups, I, however, accepted 2 promises instead of data, even though the callback from http was registered before the controller was instantiated.
QuestionsCtrl.$inect = ["DialogsService", "initialData", "QuestionsService"]; function QuestionsCtrl(DialogsService, questions, groups, QuestionsService) {
When I replaced the code with this (didn't use the initialData object, instead returned two other objects, it worked:
resolve: { questions: function (QuestionsService) { //$http call for all questions return QuestionsService.getAll(); }, groups: function (GroupsService) { //$http call for all groups return GroupsService.getAll(); } }
Does anyone have a logical explanation why, in the first case, I returned promises (despite the fact that the data was actually present on the client), and the second worked flawlessly?