1

I am working on a angular one page application and I was wondering how to feed the app with data that are dynamically generated in the server side when the page first load.

Something like this:

var bootstrapValues = {
   totalNumberOfPosts: 345,
   postsPerPage: 10,
   // etc. etc.
}

What is a good way to enter this configuration hash into the app?

Thanks

1 Answer 1

3

do it in run

app.run(function($rootScope, $http) {
    $http.get(configurationUrl).success(function(data) {
        $rootScope.bootstrapValues = data;
    }).error(function() {
    });
})
Sign up to request clarification or add additional context in comments.

3 Comments

I know angular code can be really simple, but this simple? Since $http returns a promise, can we be certain that bootstrapValues has the data when the page first loads?
it does as the success executes. You said that, it's a promise.
It should be noted though that the success callback function could be run some time after the code in the run block has executed. In this time period bootstrapValues won't have a value. I think this goes against the idea of bootstrapping.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.