【发布时间】:2014-05-27 15:18:56
【问题描述】:
我想如何在 geojson 对象中使用 angularjs 的 forEach 访问特定值
查看代码和错误:
我的geojson:
var Field = {
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "Point" },
"type": "Feature",
"properties": {
"test": "tge",
"test2": "tge"
},
"fiche": {
"id": "1",
"date_creation": "2014-04-01 00:00:00",
"date_modification": "2014-04-01 00:00:00"
},
},
{
"geometry": {
"type": "Point" },
"type": "Feature",
"properties": {
"test": "gztgt",
"test2": "gztgt"
},
"fiche": {
"id": "2",
"date_creation": "2014-04-01 00:00:00",
"date_modification": "2014-04-01 00:00:00"
},
},
]
};
js 代码(在控制器中):
/* scope alternate view */
$http({method: 'GET', url: urlDataLocalIntern}).
success(function(data, status, headers, config) {
eval(data);
$scope.alternateViewText = Field.features[];
}).
error(function(data, status, headers, config) {
alert("error ");
});
html代码:
<ul>
<li ng-repeat="alternate in alternateViewText">
<p>{{alternate.properties.test}} - {{alternate.properties.test2}}</p>
</li>
</ul>
当我这样做时,我有这个错误
错误:[ng:areq] http://errors.angularjs.org/1.3.0-beta.8/ng/areq?p0=MapCtrl&p1=not%20aNaNunction%2C%20got%20undefined 在错误(本机)
怎么了?
【问题讨论】:
-
点击错误链接,它清楚地表明您的控制器有问题。
MapCtrl is not a function, got undefined. -
当我删除 $http 时,控制器工作;为什么错误说在 $http 部分之外有错误?
-
您发布的代码 sn-ps 很难判断。尝试发布整个控制器声明。使用您的代码的 jsfiddle 也会有所帮助。
标签: javascript angularjs