AngularJS Import configuration from an external file
HTML
<script src="https://code.angularjs.org/angular-1.0.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.min.js"></script>
<div ng-app="myApp" ng-controller="TestCtrl">
My app name is <b>{{ appName }}</b> in version <b>{{ appVersion }}</b>
</div>
JavaScript
// File: app.js
// Storing multiple constant values inside of an object
var app = angular.module('myApp', []);
// File: config.js
app.constant('config', {
appName: 'My App',
appVersion: 4.0,
apiUrl: 'http://www.google.com?api'
});
// File: TestCtrl.js
// Now we inject our constant value into a test controller
app.controller('TestCtrl', ['$scope', 'config', function TestCtrl($scope, config) {
$scope.appName = config.appName;
$scope.appVersion = config.appVersion;
}]);