AngularJS: Immutable constants

using object.freeze

by thibs

HTML

<div ng-app='App'>
    <div ng-controller="testCtrl">{{const1}}
        <br />{{const2}}</div>
</div>

JavaScript

var app = angular.module('App', []);
app.constant('constants', (function () {
    var constants = {
        MY_CONSTANT: 'some value',
        MY_CONSTANT2: 'some value 2'
    };
    Object.freeze(constants);
    return constants; 
}()));


// inject them and use
app.controller('testCtrl', function ($scope, constants) {
    $scope.const1 = constants.MY_CONSTANT;
    $scope.const2 = constants.MY_CONSTANT2;
});