各位,我正在将 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/