我们,我正在将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的答案。
我怎样才能实现这一目标?
答案 0 :(得分: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>