I am building a web application in AngularJS which uses an API and some parameters
var api_params = {
api_key: "ABCDE12345",
api_base_url: "/something",
// ...
}
And I am trying to set these properties inside my angular app
through either app.value
or app.constant
, to have it in a clean way.
app.value('API_Params', {
// ...
// ...
});
I am trying to avoid setting these values in hidden inputs
<input type="hidden" name="api_key" value="ABCDE12345"/>
<!-- ... ... -->
(which I could retrieve with angular.element($selector)
), and avoid hardcoding the values
app.value('API_Params', {
api_key: "ABCDE12345",
api_base_url: "/something",
// ...
}
But no matter how much I look for it or tinker with the code, there's always an error.
This would be my ideal situation:
In my HTML:
<script>
var api_params = {
// ... as seen above
}
</script>
And in my angular app
myWebApp.value('API_Params', "Something clever here to get api_params");
Thank you!
Update: I'm trying to avoid bad practices. If you think there are other legit methods, please post your answer with recommendations.