Fahim Afser
Fahim Afser

Reputation: 13

How to read the value from web config in AngularJs Controller

<configuration>
    <appSettings>
            <add key="var1" value="SomeValue"/>
      </appSettings>
<configuration>

I want to read this var1 in angularJS controller Like this...

function ReadConfigurationSettings()
    {
        var k = '<%=ConfigurationManager.AppSettings["var1"].ToString() %>'
        alert(k);
    }

but its not working..

Upvotes: 0

Views: 2597

Answers (1)

Bill P
Bill P

Reputation: 3618

You cannot get a value from web config directly. One option is to put the value into a meta tag in your index html for example like this:

<meta name="var1" content="@ConfigurationManager.AppSettings["var1"]" />

Then you can get that value from angular like this:

var var1 = angular.element(document).find('meta[name=var1]').prop("content");

Upvotes: 1

Related Questions