【发布时间】:2017-07-25 09:08:35
【问题描述】:
控制器代码:
var myApp = angular.module('myApp', []);
myApp.controller('myController', function($scope, $http) {
$http.get('data.json').then(function(data) {
$scope.artist = data;
});
});
html代码:
<div class="main" ng-controller="myController">
<ul class="artistlist">
<li class="artist cf" ng-repeat="x in artist">
<img ng-src="images/{{x.shortname}}_tn.jpg" alt="Photo of {{x.name}}">
<div class="info">
<h2>{{x.name}}</h2>
<h3>{{x.reknown}}</h3>
</div>
</li>
</ul>
</div>
【问题讨论】:
-
控制台有错误吗?你是什么console.log(数据)?您是在为您的应用程序提供服务还是尝试直接从文件系统访问
data.json? -
console.log(data) 工作正常并显示数据:Object {data: Array(9), status: 200, config: Object, statusText: "OK", headers: function}
-
从您的错误看来,您在应用程序的某些部分使用 MyController 作为控制器的名称,在上面的 sn-p 中使用 myController
-
抱歉上面的错误我没有保存 HTML 文件现在它显示数据:对象 {data: Array(9), status: 200, config: Object, statusText: "OK",标题:函数}
标签: javascript html angularjs json controller