how to define constants for Angular JS in a different file

Viewed 25580

I want to write several constants for my Angular JS app. I want to write them in a separate file and want to access them.

I have tried with IIFE (Immediately Invoked Function Expression) like this,

constants.js

var Constants = (function () {

    var allConstants = {
        "url": 'abc',
        "name": "anijit",
        "sn": "sau"
    }

    return allConstants
})();
console.log('defined constants', Constants)

But when I have tried to access them it show Constants not defined error. Where I have done the wrong thing?

I want to access them using Constants.url in the way and I don't want to make any $http call or something like that. How to achieve that?

3 Answers
Related