我正在尝试返回一个函数的数组一次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