I want to store Url in configuration file so when I deployed this on Testing server or on Production I have to just change the url on config file not in js file but I don't know how to use configuration file in angular js
2 Answers
There are ways you can deal with it , but while coming to our implementation we used to do the following way
Create an External Environment js file
(function (window) { window.__env = window.__env || {}; window.__env.apiUrl = 'your Api Url'; }(this));In your Index.html
add env.js above the app.js
<!-- Load environment variables --> <script src="env.js"></script> In your app.js
var envr ={}; if(window){ Object.assign(envr,window.__env) } // Define AngularJS application var app= angular.module('myapp', []);
// Register environment in AngularJS as constant app.constant('__env', env);
Update:
For adding additional URl in Config File:
(function (window) { window.__env = window.__env || {}; window.__env.apiUrl = 'your Api Url'; //Another Url window.__env.baseUrl ='/'; }(this)); 2 Comments
Leena
If i want to store different url in external enviorment file then how can i do it?
Tummala Krishna Kishore
@Leena if it helps you please mark it as Answers along with the Upvote