【问题标题】:Make use of AppSettings from Web.config in AngulaJS在 AngularJS 中使用 Web.config 中的 AppSettings
【发布时间】:2018-05-28 02:07:49
【问题描述】:

伙计们,我正在将 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 中进行转换,我在谷歌上找到了一些他们提到使用 Angular Constant、Angular Services 的答案。

我怎样才能做到这一点?

【问题讨论】:

    标签: javascript c# asp.net angularjs


    【解决方案1】:

    是的,正如你提到的,你可以在你的情况下使用角度常数

    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>

    【讨论】:

    • 顺便说一句,我们如何将上传路径存储在常量中。
    • 和我上面提到的一样
    • 没有显示错误..我试过了,你能用那个值编辑你的例子吗??
    • 未终止的字符串常量。
    • 好的,我刚刚删除了结尾反斜杠字符错误消失了。非常感谢 Sajeetharan。
    猜你喜欢
    • 2016-12-27
    • 2010-09-08
    • 2012-05-30
    • 1970-01-01
    • 2011-08-26
    • 2017-10-19
    • 2012-07-31
    • 2011-09-11
    • 1970-01-01
    相关资源
    最近更新 更多