ng-init in ng-repeat shows only the last item info

前端 未结 1 1914
滥情空心
滥情空心 2020-12-06 23:29

I want to loop through items like this:

1条回答
  •  半阙折子戏
    2020-12-07 00:25

    You are overwriting gameInfo every time. So by the time it renders, it is just showing the last one three times. You need to do it more like:

    notice we pass in the prediction object, not just the id. And then you can do:

    $scope.getGame = function (prediction) {
      prediction.gameInfo = {};
      $http.get('/games/' + game_id)
      .success(function (data) {
        prediction.gameInfo = data;
      });
    };
    

    And thin in your html, instead of gameInfo.whatever you will do prediction.gameInfo.whatever, that way each prediction has it's own variable, and you aren't overwriting your single copy of that variable.

    For example:

    {{gameInfo.play_at | date: 'd.MM HH:mm'}}
    

    would become

    {{prediction.gameInfo.play_at | date: 'd.MM HH:mm'}}
    

    0 讨论(0)
提交回复
热议问题