【发布时间】:2017-04-20 18:19:49
【问题描述】:
AngularJS V1.6.4
$scope.aCourse["name"] 已正确记录到控制台,但在 HTML 代码中没有填充到屏幕中。
$scope.getCourse = function(idd){
$http.defaults.headers.common['Authorization'] = 'Basic ' + btoa($cookieStore.get('username') + ':' + $cookieStore.get('password') );
$http({
method: 'GET',
url: 'http://localhost:8080/course/'+idd,
}).then(function successCallback(response) {
$scope.aCourse = response.data;
console.log($scope.aCourse["name"]);
window.location = "/website-take-course.html";
}, function errorCallback(response) {
alert("Course data in fetching failed");
});
}
HTML 代码:
<div class="page-section padding-top-none" ng-repeat="c in aCourse" >
<div class="media media-grid v-middle">
<div class="media-left">
<span class="icon-block half bg-blue-300 text-white">1</span>
</div>
<div class="media-body" >
<h1 class="text-display-1 margin-none" >{{c.name}}</h1>
</div>
</div>
<br/>
<p class="text-body-2">{{c.description}}</p>
</div>
【问题讨论】:
-
发布你在console.log $scope.aCourse时看到的json
-
在开发者工具 - 控制台查看错误,或在网络选项卡中查看返回的响应是什么
-
你为什么要遍历一个 object (
ng-repeat="c in aCourse") 这是错误的。而是尝试{{ aCourse.name }} -
你检查答案了吗
标签: javascript html angularjs json