0

I'm new to angular js. Is it possible to reuse the constants defined in the same file like below. If not please let me know a better way to reuse the defined constants. My intention behind this is I should be able to use LoginQuery.url in my service instead of concatenating.

angular.module('myApp.constants', []).
constant('ServerConfig', {
    'url': 'http://localhost:3000/'
}).
constants('LoginQuery', {
        'url': ServerConfig.url + "/login"
    }
);

Thanks

1 Answer 1

1

I tend to do this the following way:

angular.module('myApp.constants', [])
.constant('urlsConst', (function(){
  var protocol = 'http://';
  var domain = 'www.mydomain.com';
  var base = '/api/';

  return {
    category:               protocol + domain + base + 'category/',
    home:                   protocol + domain + base +  'home/',
    products:               protocol + domain + base + 'products/'
  }

})()
);

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.