javascript - 在 AngularJS 中使用 Web.config 中的 AppSettings

标签 javascript c# asp.net angularjs

各位,我正在将 asp.net c# 应用程序转换为 AngularJS,但问题是如何在 Angular 中保留 web.config 中的 AppSettings。

<appSettings>
    <!--DEBUG MODE-->
    <add key="AppID" value="pkDesk" />
    <add key="UserID" value="Prashanth" />
    <add key="UploadPath" value="\\pk\AttachmentsUpload\" />
</appSettings>

我希望它转换为纯 AngularJS,我在 google 上找到了一些答案,他们提到使用 Angular Constant、Angular Services。

我怎样才能实现这个目标?

最佳答案

是的,正如您提到的,您可以在您的情况下使用 Angular 常数

var mainApp = angular.module("mainApp", []);
mainApp.constant('AppID', 'pkDesk');
.....
etc

演示

var app = angular.module("constantApp", []);
    app.constant('AppID', "pkDesk");
    app.constant('UserID', "Prashanth");
    app.controller('constantController', function($scope, AppID, UserID) {    
      console.log(UserID);   
      $scope.appID = AppID;
      $scope.userId = UserID;    
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<html>
<head>
  <title>Angular JS Services</title>

  <script>
  </script>
</head>
<body ng-app="constantApp">
  <div ng-controller="constantController">
    <h2>define constant in angularjs</h2>
    <div>URL: {{appID}}</div>
    <div>Title : {{userId}}</div>
    
  </div>

</body>

</html>

关于javascript - 在 AngularJS 中使用 Web.config 中的 AppSettings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47805659/

相关文章:

javascript - 当所有 jQuery promise 返回时

c# - 使用 XML 获取所有同名元素的内容?

c# - 设置在根 SignalR 端点上显示的 HTML

c# - 有人能告诉我为什么我的标题没有出现在 asp.net c# 中吗?

asp.net - 中等信任度的 LDAP

javascript - Node 为何在此基准测试中速度如此之快?

javascript - 在 .click(function () {? 中使用 $.ajax

javascript - KendoDropDownList TabIndex 不生效

c# - 为什么在部分 View 输入上显式设置名称属性会导致值在 POST 后发生变化?

asp.net - 使用 <pre> 标签时,文本超出父级 <asp :label> border