Say I am building a C# application with AngularJS.
I want to set up configuration object that es from server side and basically inject that configuration into a factory. Where the factory resides in another .JS file.
How would go about doing that?
I have a JS fiddle example set up here:
/
Say I am building a C# application with AngularJS.
I want to set up configuration object that es from server side and basically inject that configuration into a factory. Where the factory resides in another .JS file.
How would go about doing that?
I have a JS fiddle example set up here:
http://jsfiddle/f89tS/7/
Share Improve this question asked Aug 16, 2012 at 19:26 Chi ChanChi Chan 12.4k9 gold badges35 silver badges52 bronze badges2 Answers
Reset to default 9You could use module's constants for configuration objects ing from the server. Using constants is pretty easy, you could generate this on the server-side:
app.constant('CONSTANTS', {zoomLevel: 8});
and then, in your factory you can inject constants:
app.factory('map', function(CONSTANTS){
return {
zoomLevel: CONSTANTS.zoomLevel
};
});
Constants are really good for the server-generated settings since, once generated and sent to the client those can't change.
Finally, here is the working jsFiddle: http://jsfiddle/pkozlowski_opensource/JZcys/1/
Here is an example of how I acplished something similar by wrapping my bootstrap call around my own run method.
It then uses a naming convention to inject configuration options inline from your aspx page, which could be set via c# property.
I don't know if this is the 'angular' way, but it has worked well thus far.
http://jsfiddle/xpressivecode/dVM9b/