var myModule = angular.module('ExampleApp', []); myModule.constant('CONSTANTS', (function () { var constants = {}; constants.VERSION = '1.2.3'; constants.URL = 'http://www.example.com/' + constants.VERSION + '/'; constants.API_URL = 'http://api.example.com/' + constants.VERSION + '/'; return constants; }())); myModule.controller('DemoController', function (CONSTANTS, $scope) { $scope.constants = JSON.stringify(CONSTANTS, null, 2); });
<div ng-app="ExampleApp"> <div ng-controller="DemoController"> <pre> Constants: {{constants}} </pre> </div> </div>