Reputation: 4561
Given the following code:
http://jsfiddle.net/mL4Lfmox/1/
I want to develop a constant variable storage in angular that all controllers, directives and services in the root scope can access. However when running the following code it tells me the constant I'm referencing is undefined (test_url)
var myapp = angular.module('myapp', []);
myapp.constant("myConfig", {
"test_url": "http://localhost"
})
myapp.controller('testCtrl', ['$scope', function ($scope, myConfig) {
$scope.url = myConfig.test_url;
}]);
HTML
<div ng-app="myapp">
<fieldset ng-controller="testCtrl">
<p>{{ url }}</p>
</fieldset>
</div>
Upvotes: 0
Views: 20
Reputation: 2304
You have an error in your dependency injection params:
myapp.controller('testCtrl', ['$scope', 'myConfig', function ($scope, myConfig) {
$scope.url = myConfig.test_url;
}]);
This should works.
Upvotes: 1