【发布时间】:2017-08-16 23:15:24
【问题描述】:
我有这段代码,但我不知道为什么,但是 ng-repeat 指令被注释并且不显示 JSON 对象的结果。我检查了对象是否通过 toSource() 方法正确传递给“this.paises2”,看起来一切都很好。
我在这里检查过,但没有任何效果:
AngularJS: ng-repeat not displaying JSON
ng-repeat code getting commented out when viewed from browser
ngRepeat div get commented out when i see from the browser inspector
这是 HTML 代码:
<html ng-app="miModulo">
<head>
<link href="mis-css.css" rel="stylesheet" type="text/css">
</head>
<body ng-controller="miControlador as vm">
<button ng-click="vm.buscarEnRegion()">Pulsar</button>
<ul ng-repeat="elemento in vm.paises">
<li>
{{elemento.name}}
</li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="mijs1.js"></script>
</body>
还有 Javascript/Angular JS 代码:
angular
.module("miModulo",[])
.controller("miControlador",['$http',funcionPrincipal] );
function funcionPrincipal($http)
{
this.buscarEnRegion=function()
{
$http.get("https://restcountries.eu/rest/v1/region/africa").then(function(miRespuesta)
{
this.paises=miRespuesta;
// alert(miRespuesta.toSource());
alert(this.paises.toSource());
},function(miRespuesta)
{
alert("incorrecto");
}
); //then
}
}
提前致谢。
【问题讨论】:
-
你能创建一个 JSFiddle 吗?
-
将 ng-repeat 从 ul 更改为 li
标签: javascript angularjs json angularjs-ng-repeat