2015-10-08 12 views
6

एपीआई से शराब रिकॉर्ड आउटपुट निर्देश दोहराएं। मैं शराब एपीआई जो तब मेरी नियंत्रक में पहुँचा जा सकता है सेवा करने एक कारखाने कार्य होत्रुटि: [ngRepeat: dupes] इसका क्या अर्थ है?

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

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

} 

नियंत्रक:

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 आइटम के साथ डोम नोड्स को जोड़ने के लिए कुंजी का उपयोग करता है।

इसका मतलब है कि $ scope.wines में कुछ मान हैं जो डुप्लिकेट हैं।

आप भी इस पद का उल्लेख कर सकते हैं: Angular ng-repeat Error "Duplicates in a repeater are not allowed."

+0

धन्यवाद लेकिन यह अभी भी मेरे लिए कोई मतलब नहीं है। इसके अलावा मैंने HTTP अनुरोध के अंत में http://www.greatwines.9000.com/wines भी जोड़े और किसी कारण से यह अब काम करता है। मैं इन रहस्यमय कीड़े और angularjs के साथ फिक्स में आ रहा है। यह बहुत संगत नहीं है। – HGB

संबंधित मुद्दे