0

My AngularJs Code:

var Customer = '<%=ConfigurationSettings.AppSettings["CusID"]%>';
alert(Customer);

Web Config Code:

<configuration><appSettings><add key='CusID' value='POKA' /></appSettings></configuration>

I want to get Web config app settings values from my angular js controller.Can anyone help me for this.

Thanks

halfelf
  • 9,737
  • 13
  • 54
  • 63
  • You could use ng-init in your html to initiate a variable in your controller from the markup, instead of from the controller. https://docs.angularjs.org/api/ng/directive/ngInit – Urielzen Mar 26 '19 at 04:48

1 Answers1

0

Create a service to read settings ,

 using AngularClient.ViewModel;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Options;

    namespace AngularClient.Controllers
    {
        [Route("api/[controller]")]
    public class ClientAppSettingsController : Controller
    {
        private readonly ClientAppSettings _clientAppSettings;

        public ClientAppSettingsController(IOptions<ClientAppSettings> clientAppSettings)
        {
            _clientAppSettings = clientAppSettings.Value;
        }

        [HttpGet]
        public IActionResult Get()
        {
            return Ok(_clientAppSettings);
        }
    }
}

then call that service to get values .

  configClient() {

    // console.log('window.location', window.location);
    // console.log('window.location.href', window.location.href);
    // console.log('window.location.origin', window.location.origin);

    return this.http.get(window.location.origin + window.location.pathname + '/api/ClientAppSettings').map(res => {
        this.clientConfiguration = res.json();
    });
}

angular-configuration-using-asp-net-core-settings

app-settings-the-angular-way

Jophy job
  • 1,924
  • 2
  • 20
  • 38