var app = angular.module('plunker', []);
app.run(function($http, $rootScope){
$http.get('config.json').
success(function(data, status, headers, config) {
$rootScope.config = data;
$rootScope.$broadcast('config-loaded');
}).
error(function(data, status, headers, config) {
alert('error');
});
})
app.controller('MainCtrl', function($scope, $rootScope) {
$scope.name = 'Viblo';
$scope.$on('config-loaded', function(){
$scope.name = $rootScope.config.name;
});
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.3.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.7/angular.js" data-semver="1.3.7"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<p>Hello {{config.name}}!</p>
</body>
</html>
/* Put your css in here */
{
"name":"Cùi Bắp"
}