0
鑑於以下代碼:角1.X存儲常量,可以是在根範圍訪問
http://jsfiddle.net/mL4Lfmox/1/
我想開發中的常量變量存儲在角所有控制器,指示和服務在根範圍可以訪問。運行下面的代碼然而,當它告訴我,我引用的常量是不確定的(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>