繁体   English   中英

无法使用angularjs从json文件中检索数据

[英]unable to retrieve data from json file using angularjs

无法使用angularjs从json文件中检索数据,我正在尝试从json文件中检索数据,这是我的代码

<!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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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