I have a task like in this question. But the main difference is that I need two controllers for two different routes. Something like two different tables. ../table1 and ../table2. A data in each table must queried from google cloud endpoints (via gapi). How can I adapt an initialisation sequence for my situation? Also, I want have a possibility for deep linking: user may start from /table1 instead of "root path".
Asked
Active
Viewed 196 times
0

Community
- 1
- 1

Ilya Moskvin
- 1
- 1
-
Are you aware with ui-router https://github.com/angular-ui/ui-router With this you can define states with its own controllers and url patterns. – erandac Jan 14 '15 at 12:11
-
Yes, I use the ui-router and can define controller for each url. My question is: how can I initialise each controller whis some data from google endpoints. Where place $window.initGapi function and how this could work? – Ilya Moskvin Jan 14 '15 at 12:16
-
You can create a service which wraps the google api object, On controllers or resolves, you can inject the service you created. As mentioned in the question you reffed, you might need lazy boostrap of anguler app. (in the googleOnLoadCallback function) – erandac Jan 14 '15 at 12:33
-
Check the documentation here for Deferred Bootstraping. https://docs.angularjs.org/guide/bootstrap – erandac Jan 14 '15 at 12:39
-
Yes, I try this way but dont undestand details. So, I have global function var init = function() { window.initGapi(); } which called after gapi lib loaded. Where I need to define window.initGapi() method? In previous question this method was defined in the single controller like that: $window.initGapi = function() {gapiService.initGapi(postInitiation);} And how can I do the same effect for several different controllers? – Ilya Moskvin Jan 14 '15 at 13:42
1 Answers
0
You can use 'resolve' to get data from external service, Then inject the names of resolves to controller as same way service get injects. Note that you can inject the resolves to the controller that attached to state only. Check the documentation here https://github.com/angular-ui/ui-router/wiki#resolve
Eg;
$stateProvider.state('myState', {
resolve:{
googleData: function($http){
return $http({method: 'GET', url: '/someUrl'});
}
},
controller: function($scope, googleData)
{
$scope.simple = googleData.value;
}
})

erandac
- 575
- 5
- 8