AngularJS ng-repeat-http.gs检索数据,但不显示 [英] AngularJS ng-repeat - http.gs retrieving data, but not displaying
问题描述
我是angular的新手,正在尝试将其集成到我的应用程序中.我正在尝试对.JSON文件使用简单的$http.get
,该文件在ng-repeat
I am new to angular and trying to integrate it within my application. I am attempting to use a simple $http.get
to a .JSON file, which displaying the matching contents in a ng-repeat
我得到了:
$scope.countries = [];
$http.get('/resources/data/countries-report.json').success(function(data) {
$scope.countries = data.countries;
// alert(JSON.stringify($scope.countries));
console.log(data.countries);
console.log(data.countries.population);
}).error(function(error) {
alert('error');
});
这是我的.JSON文件:
Here's my .JSON file:
{
"firstName" : "Joe",
"surName" : "Bloggs",
"countries" : [
{ "name": "France", "population": "63.1" },
{ "name": "Span", "population": "52.3" },
{ "name": "United Kingdom", "population": "61.8" }
]
}
这是我的HTML:
<li ng-repeat="country in countries">
{{country.name}} has population of {{country.population}}
</li>
在浏览器中查看时,显示的全部是:
When viewing in the browser, all that is displayed is:
- 人口
- 人口
- 人口
似乎我的代码可以看到3个国家/地区,当我在.JSON文件中添加或删除时,HTML中的列表会相应地进行修改,但是.JSON的内容未显示.
It seems as though my code can see there are 3 countries, as when i add or remove from my .JSON file, the list in the HTML modifies accordingly, however, the contents of the .JSON is not displaying.
我忘了从我的.get
??
**更新*************************
正如某些人提到的那样,我的代码似乎是正确的,我想我知道可能是什么问题.
As some have mentioned, my code seems to be correct, i think i know what the problem may be.
我的应用程序使用了Swig的HTML模板结构,该结构使用{{}}访问.JSON文件.这是否会导致与Angular混淆?
My application makes use of a HTML templating structure using Swig which accesses .JSON file using {{ }}.. Could this be causing confusion with Angular?
**更新*************************
如果我更改:
var app = angular.module("app", []);
到
var app = angular.module('app', []).config(function($interpolateProvider){
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
}
);
并且:
<li ng-repeat="country in countries">
{{country.name}} has population of {{country.population}}
</li>
收件人:
<li ng-repeat="country in countries">
{[{country.name}]} has population of {[{country.population}]}
</li>
然后显示正确的值.
推荐答案
您必须以
[
{
id:1,
ima:gh.jpg,
data:
[
{
anotherid:1,
my:w,
ki:y
}
]
},
{
id=2,
ima:jh.jpg
}
]
这篇关于AngularJS ng-repeat-http.gs检索数据,但不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!