简体   繁体   中英

unable to retrieve data from json file using angularjs

unable to retrieve data from json file using angularjs, I'm trying to retrieve data from json file here is my code

<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl"> 

<ul>
<li ng-repeat="x in names">
{{ x.eng_rev_type + ', ' + x.year_end }}
</li>
</ul>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://preview.sokrati.com/data/open_spendings.json")
.success(function (response) {$scope.names = response.data;});
});
</script>

</body>
</html>

尝试在收到响应后调用$ apply。

if(!$scope.$$phase) $scope.$apply();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM