0

I have a Facebook login button in my app that uses 'angular-facebook' module. In my .config block I have following code:

FacebookProvider.init('myAppId');

Now I have service that is loading myAppId from DB via REST api but I dont know how to correctly load it and pass it in .config block.

I spent last 2 hours reading manuals angd googling how to do this but I am still confused how to make this work.

4
  • Paste some code in your question and show us what you have done so far. Commented Sep 14, 2015 at 10:29
  • The question is quite simple an I assume you know how Angular service looks like. Commented Sep 14, 2015 at 10:45
  • 1
    you can implement provider recipe so you can use it in your app's config phase. here is fiddle :jsfiddle.net/jugnu_pathak/Le4qqz5b/2 Commented Sep 14, 2015 at 10:50
  • Ok got it working now, I had to learn a little more about provider and promises :-) Thanks for tips. Commented Sep 17, 2015 at 12:58

2 Answers 2

1

You can retreive the $http service by using angular injector, and then, configure your app, something like this :

(function() {


     angular.element(document).ready(function() {
           var initInjector = angular.injector(["ng"]);
           var $http = initInjector.get("$http"); 

            $http.get("/myFbAppId.json").then(function(response) {
               angular
                  .module('myApp')
                  .config(function(facebookProvider){
                      FacebookProvider.init(response.data.myAppId);
                  })  

                  angular.bootstrap(document, ['myApp']);
            })

     });

}());
Sign up to request clarification or add additional context in comments.

Comments

0

Only providers and constants can be injected into configuration blocks in order to prevent instantiating services before they have been fully configured. You basically can only inject providers and constants in your config block. So the only solution is not to do it in a config block but in a run block.

1 Comment

Thanks, so if I use some library that requires init values for its provider in config block there is no way to load these from api somehow?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.