Passing initial settings to the app.

26 views
Skip to first unread message

Newen F

unread,
Jul 22, 2016, 11:22:56 AM7/22/16
to AngularJS
I've been googling this for a while now  but can't find the info I'm looking for.

All search results I find are about passing info between components and the like, but I need to find out how to add some initial values to the app.

My thought are to add those values to the bootstrapping, but I haven't found a specific way to do it yet.

What i'm trying to do is add a javascript object called "mySettings" to the app, so that some initial things can be processed.

I've considered putting these settings into a settings.json file, but I'd rather not make an extra call. The settings are already being printed into the html via php so it makes sense to have them there already.

Some of the info might be stuff like User info and app settings. (user gets to the app after login into the website)

Sander Elias

unread,
Jul 22, 2016, 1:43:21 PM7/22/16
to AngularJS
Hi Newen,

Have you considered SSI? (server side include). Just let the server put a little script tag in the index.html, that you then can read from your bootstrap code?

Regards
Sander

Newen F

unread,
Jul 25, 2016, 5:30:53 AM7/25/16
to AngularJS
Hey Sander. Thanks for the heads up.

Is SSI the same as server side rendering? I didn't know this was possible with A2. So that's cool to know. I'm looking into it.

Though I expected this to not be so hard. I mean, I just have a js object, or a json string with a bunch of parameters and I want my app to have that info when initializing.

Sander Elias

unread,
Jul 25, 2016, 10:23:07 AM7/25/16
to AngularJS
Hu Newen,

For the sake of this argument, yes, you can see it as the same. (technically, it isn't.)

Thing is, it easy enough to fetch a config, but usually one needs this during config/boot (before angular becomes active). At that time $http is'n usable yet. So you have to use what the browser provides. If you target modern browsers, you might use fetch. the goog old XMLHttpRequest is of coarse also available to you. I don't mind using XMLHttpRequest directly, but apparently that puts me in a minority ;)

Regards
Sander


Newen F

unread,
Jul 25, 2016, 11:12:22 AM7/25/16
to AngularJS
hehe. yeah, true. and that is precisely what i'm trying to avoid, that extra call, as it is really not necessary.

My particular context is that I'm updating a flash app to HTML5 and the flash app currently uses flashVars to set initial values and parameters.

The flashVars object is already being printed in the html with PHP. So when the page loads, it already has all that info. The flash app has access to that info via the flashVars object.

I was trying to emulate something similar, by having this info in a JS object (or array) and supply this object to the A2 app when bootstrapping it.

As I see it, using $http or XMLHttpRequest or any other "after app initialization" method is really extra steps. Or am I to influenced by the flashVars object method and it's just me being stubborn by not wanting to let go?  lol

Regards.
Newen

Sander Elias

unread,
Jul 25, 2016, 12:21:08 PM7/25/16
to AngularJS
Hi Newen,

No, the SSI method is the most efficient way to get data into your app. It saves you a round-trip. I believe there is an sample in this group somewhere that goes a bit deeper into this. (I recall writing about this before ;) )

Regards
Sander
Reply all
Reply to author
Forward
0 new messages