2015-10-08 6 views
6

apiからワインレコードを出力するリピートディレクティブ。私はその後、私のコントローラでエラー:[ngRepeat:dupes]これはどういう意味ですか?

app.factory("Wine", function ($http){ 
    var factory = {}; 

    //getWines 
    factory.getWines = function(){ 
     return $http.get("http://www.greatwines.9000.com") 
    } 

} 

コントローラにアクセスされるワインのAPIまで提供するために、工場の機能を持っている:

app.controller("winesCtrl", function($scope, $http, Wine){ 
     Wine.getWines() 
     .success(function(wines){ 
      $scope.wines = wines; 
     }) 
     .error(function(){ 
      alert("Error!"); 
     }); 
    }); 

VIEW: 

<h2>Wine list</h2> 
    <div class="row margin-top-20 wine-container" ng-repeat="wine in wines"> 
     <div class="col-sm-3"> 
      <img src="{{wine.picture}}" class="img-responsive" /> 
     </div> 
     <div class="col-sm-9"> 
      <div class="margin-top-20"> 
       <span class="bold">Name: </span><span>{{wine.name}}</span> 
      </div> 
      <div> 
       <span class="bold">Year: </span><span>{{wine.year}}</span> 
      </div> 
      <div> 
       <span class="bold">Grapes: </span><span>{{wine.grapes}}</span> 
      </div> 
      <div> 
       <span class="bold">Country: </span><span>{{wine.country}}</span> 
      </div> 
      <div> 
       <span class="bold">Region: </span><span>{{wine.region}}</span> 
      </div> 
      <div> 
       <span class="bold">Price: </span><span>{{wine.price}}</span> 
      </div> 
      <div> 
       <span class="bold">{{wine.description}}</span> 
      </div> 
      <div class="margin-top-20"> 
       <a href="#/wines/{{wine.id}}" class="btn btn-default">Edit Wine</a> 
      </div> 
     </div> 
    </div> 

を私はこのエラーをクリックし、「曖昧」angularjs典型的なやり方で、私はこれを取得します:

Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: wine in wines, Duplicate key: string:e, Duplicate value: e 

これはどういう意味ですか?ワインは「ワイン」と同じではないので、なぜそれが重複していると思いますか?

答えて

10

ngRepeat式に重複するキーがある場合に発生します。 AngularJSはキーを使用してDOMノードをアイテムに関連付けているため、重複キーは使用できません。

これは、$ scope.winesにいくつかの値が重複していることを意味します。

また、この記事を参照してくださいすることができますAngular ng-repeat Error "Duplicates in a repeater are not allowed."

+0

おかげで、それはまだ私には意味がありません。また、HTTPリクエストの最後にhttp://www.greatwines.9000.com/winesを追加しました。何らかの理由でこれが動作します。私はこれらの不思議なバグやanglejsを修正していきます。あまり一貫しているわけではありません。 – HGB

関連する問題