2014-06-11 1 views
1

는이 같은 항목을 통해 루프를 원하는 보여줍니다NG-초기화에서 NG-반복 마지막 항목이 정보

<section class="col-sm-4" data-ng-controller="PredictionsController" data-ng-init="findMyPredictions()"> 
    <div class="games"> 
     <div class="game-row" ng-repeat="prediction in predictions" ng-init="getGame(prediction.game_id)"> 
      <a class="button primary alt block" href="#!/predictions/{{prediction._id}}"> 
       <span class="home flag {{gameInfo.team1_key}}"></span> 
     <span class="middle"> 
      <span class="date">{{gameInfo.play_at | date: 'd.MM HH:mm'}}</span> 
      <span class="versus">{{gameInfo.team1_title}} - {{gameInfo.team2_title}}</span> 
     </span> 
       <span class="away flag {{gameInfo.team2_key}}"></span> 
      </a> 
     </div> 
    </div> 
</section> 

그러나 출력은 X 시간에 동일한 정보입니다 : 요청이 있지만 enter image description here 을 올바르게 완료 : enter image description here

무엇이 잘못 되었습니까?

UPDATE : 내 getGame 기능 : 당신은 gameInfo 때마다 덮어 쓰는

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

}; 

답변

6

. 렌더링 할 때까지 마지막 세 번을 3 번 보여줍니다. 우리가 prediction 객체를 전달

<div class="game-row" ng-repeat="prediction in predictions" ng-init="getGame(prediction)"> 

통지 만이 아니라 ID를 : 당신은 더 같이 할 필요가있다. 그리고 당신은 할 수 있습니다 :

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

그리고 얇은

당신의 HTML에 대신 gameInfo.whatever 당신은 prediction.gameInfo.whatever, 각각의 예측은 자신의 변수, 그리고 그 변수의 당신의 단일 복사본을 덮어 쓰기되지 않습니다이 그런 식으로 할 것입니다. 예를 들어

: 내 기능을 볼 수 있도록

<span class="date">{{gameInfo.play_at | date: 'd.MM HH:mm'}}</span> 

<span class="date">{{prediction.gameInfo.play_at | date: 'd.MM HH:mm'}}</span> 
+0

그것은 나를 위해 작동하지 않는 될 것입니다, 나는 내 질문에 업데이트되었습니다. 의견 있으십니까? – Algeron

+0

'prediction.gameInfo = {}; '명령이 정말로 필요합니까? –