AngularJS V1.6.4不能在HTML
$ scope.aCourse [「名稱」]訪問嵌套的JSON對象被記錄到正確的安慰,但在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 – Sajeetharan
去看看在開發工具的JSON - 控制檯的錯誤,或在網絡選項卡看看返回的響應是什麼 –
爲什麼你重複一個**對象**('ng-repeat =「c在aCourse」')這是錯誤的。而是嘗試'{{aCourse。姓名}}' –