-2

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

1

2 Answers 2

3

You can use angular.constant for configurations.

app.constant('appConfigurations', { link_url: "http://localhost:8080/api", //For production u can simply change the link_url //link_url: "http://production_url/api" }); 
Sign up to request clarification or add additional context in comments.

Comments

1

There are ways you can deal with it , but while coming to our implementation we used to do the following way

  1. Create an External Environment js file

    (function (window) { window.__env = window.__env || {}; window.__env.apiUrl = 'your Api Url'; }(this)); 

  2. In your Index.html

add env.js above the app.js

<!-- Load environment variables --> <script src="env.js"></script> 
  1. 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

If i want to store different url in external enviorment file then how can i do it?
@Leena if it helps you please mark it as Answers along with the Upvote

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.