2

I have defined constant in my application as follows,

angular.module('configuration', [])
 .constant('Engine_API', 'http://sample.io:1929/')

And i am using in the application as follows,

var testApp = angular.module('Duot', [ 'configuration']
testApp .controller('userProfileCtrl', function ($scope,Engine_API) {
}

is there a way i can modify and set a new value to the constant in run time?

5
  • 5
    Kindof by definition, given that it is a constant, you cannot. Commented Sep 28, 2016 at 18:35
  • If you are looking for easy updatable central storage, consider using a value. .value('myData', { Engine_API: 'http://sample.io:1929/' }); You can then access and update myData.Engine_API as desired. Commented Sep 28, 2016 at 18:38
  • Why you not create a dataservice to share some general data? Commented Sep 28, 2016 at 18:43
  • Constants are great for values that never change Commented Sep 28, 2016 at 19:15
  • or use a provider which you can set at run time Commented Sep 28, 2016 at 19:54

1 Answer 1

3

You can not change angular constant value. But if you want to change value, you can use angular value provider instead of constant.

angular.module('configuration', [])
 .value('Engine_API', 'http://sample.io:1929/')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.