0

I'm trying to define a function to hold the constant but is not working

(function(){
'use strict';

angular
    .module('app')
    .constant('config1', config1)
    .constant('config2', 
        (function(){
            return {
                VERSION: 2
            }
        }())
    );

function config1() {
    return {
        VERSION: '1'
    }
};

})();

console.log(config1.VERSION); // undefined

console.log(config2.VERSION); // 2

3
  • what problem are you trying to solve by trying to do this? It sounds like you need to create a provider which can be modified in config phase Commented Sep 30, 2015 at 22:56
  • for one, you haven't defined the variable config1, which you are passing to .CONSTANT() Did you mean to pass config2, or name the config2 function config1? Commented Sep 30, 2015 at 23:02
  • config1, looks like you've referenced the func without () compared to config2 where you use () in which case it will execute... Commented Sep 30, 2015 at 23:28

1 Answer 1

1

I think u missed the config1**()**.VERSION;

Sign up to request clarification or add additional context in comments.

1 Comment

that works. is this the right way to create and use constants? thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.