javascript - Making a GET request in AngularJS's config -


similar question here doesn't appear work in case. i'm using angular-ui's google maps api, requires configuration so:

.config(function(uigmapgooglemapapiprovider) {     uigmapgooglemapapiprovider.configure({         //    key: 'your api key',         v: '3.20', //defaults latest 3.x anyhow         libraries: 'weather,geometry,visualization'     }); }) 

i don't want have api key directly in here, i'd load in server using route via request ('/api/googleapi'). however, when try:

 .config(function($http, uigmapgooglemapapiprovider) { 

i get:

 failed instantiate module myapp due to: error: [$injector:unpr] unknown provider: $http 

are there workarounds or should brazenly chuck api key in here?

based on @ryeballar's suggestion

after reading link @ryeballer provided in comments other answer, there simpler workaround doesn't require mess pre-bootstrapping processing or xmlhttprequests or suggested in atypical solution above.

.config(function(uigmapgooglemapapiprovider) {      var $injector = angular.injector(['ng'])     var $http = $injector.get('$http')      $http.get(<url key>)     .then(function(rsp){         var data = rsp;         uigmapgooglemapapiprovider.configure({             key: data.key,             v: '3.20', //defaults latest 3.x anyhow             libraries: 'weather,geometry,visualization'         })      }) }) 

i'd argue should selected answer given it's simplicity , operates within typical angular post-bootstrapping lifecycle


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -