Reputation: 1489
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.
<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.
How can i achieve this??
Upvotes: 0
Views: 605
Reputation: 222582
Yes as you mentioned , you can use angular constant in your case
var mainApp = angular.module("mainApp", []);
mainApp.constant('AppID', 'pkDesk');
.....
etc
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>
Upvotes: 1