1
我有一个国家的JSON文件,现在我在控制台中获取数据,但它没有打印在html文件中。它显示在控制台中,但在html文件中没有打印。 所以我可以在我的html文件中调用数据。 如何从json中使用http获取数据在angularjs中
var app = angular.module("myApp", []);
app.controller('myController', function($scope,$http) {
$http.get(".../../assets/json/country.json").
then(function(data){
var countryData = data;
var conData = countryData.data;
for(var i=0; i<conData.length; i++){
$scope.countries = conData[i];
\t console.log($scope.countries.name+ " " +$scope.countries.code);
} \t \t \t \t
})
});
<html>
<head>
<title>Angular JS Controller</title>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myController">
<div ng-repeat="country in countries">
{{country.code}}
{{country.name}}
</div>
</div>
</body>
</html>
我已经加入了$ http和还得到在控制台中的数据,但在HTML它不工作 – ns093
@ ns093我已经更新答案。我已经稍微更改了代码,希望它更简洁一点。 –
我得到了答案,如果我们在html中使用这样的话,那么它的工作,