c# - Access web.config appsettings from Angular js 2 Typescript -


i new angular js 2 type script programming. trying find out way access app settings keys of web.config typescript. wouldn't want hardcode data in type script vary across environments. tia

typescript compiled javascript later gets executed within context of application consuming web.config file. because of this, won't able read configuration @ typescript level.

what need instead make configuration available @ runtime. in other words, whatever code generated typescript needs aware of object available while page running feed configuration may need.

there few ways this.

you make js code aware of object should exist in global context (e.g. appconfig in js when page running). can populate object settings. example asuming razor:

var appconfig = []; appconfig.adminemail = '@configurationmanager.appsettings["adminemail"]'; 

then typescript code can rely on variable appconfig @ runtime.

alernatively, can device way page inject configuration code generated typescript:

var adminemail;  function setadminemail(val: string)  {     adminemail = val; }  function displayadminemail()  {     alert(adminemail); } 

then in page:

<script type="text/javascript">     setadminemail('@configurationmanager.appsettings["adminemail"]');     displayadminemail(); </script> 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -