[英]Make use of AppSettings from Web.config in AngulaJS
I guys, I'm converting asp.net c# application to AngularJS but the problem is how I can keep AppSettings from web.config in Angular. 伙计们,我正在将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>
I want it to convert in pure AngularJS, I have found some of Answer on google they have mentioned to use Angular Constant, Angular Services. 我想将其转换为纯AngularJS,我在他们提到的Google上找到了一些使用Angular常数,Angular Services的Answer。
How can i achieve this?? 我怎样才能做到这一点?
Yes as you mentioned , you can use angular constant in your case 是的,正如您所提到的,您可以使用角度常数
var mainApp = angular.module("mainApp", []);
mainApp.constant('AppID', 'pkDesk');
.....
etc
DEMO DEMO
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.