我正在嘗試返回一個函數的數組一次onClick被觸發。我在控制檯中看到數組中包含的值。但是我看不到HTML頁面上顯示的值。
控制器:
$scope.chosenFilm = []; //The array where values are stored
//onClick function
$scope.insertFilm = function() {
console.log("Film saved in watch list!");
getSelectedFilm(); //Call function
}
function getSelectedFilm() {
return $http.get('/watch-list').then(function(response) {
$scope.chosenFilm = response.data;
$log.info($scope.chosenFilm[0]); // Values displayed in console!
return $scope.chosenFilm;
});
}
HTML頁,其中將顯示值:
<div class="container">
<table class="table">
<thead>
<tr>
<th>Film</th>
<th>Poster</th>
<th>Overview</th>
<th>Genres</th>
<th>Release</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="film in chosenFilm">
<td>{{film.title}}</td>
<td><img ng-src="{{film.poster}}"></td>
<td>{{film.overview}}</td>
<td>{{film.genres}}</td>
<td>{{film.release | date: "dd.MM.y" : UTC+00:00 }}</td>
</tr>
</tbody>
</table>
</div>
你說的是HTML的地方使用哪個控制器? –
嘗試在'http'服務之前移除'return'。也不需要返回數組。只要足夠'$ scope.chosenFilm = response.data;' –
@Hadi,但這在這種情況下不是問題。它不應該干擾元素的渲染 – lealceldeiro