Ionic "track by" error with tinder cards -
i started learning ionic 2 weeks ago , right creating small project practice.you can download project github : https://github.com/kaanyildirim/ionictest
i trying use tinder cards created ionic team itself. (https://github.com/driftyco/ionic-ion-tinder-cards)
i have tried every possible solution "track by" expression still getting error:
error: [ngrepeat:dupes] duplicates in repeater not allowed. use 'track by' expression specify unique keys. repeater: card in cards track card.id, duplicate key: undefined, duplicate value: undefined
i have tried fix error "track $index" , "track card.id "(every card has "id" attribute in .json file) didn't worked. guess made small mistake , can't find it.
can please me? thanks
index.html:
<td-cards> <td-card ng-repeat="card in cards track card.id" on-destroy="carddestroyed($index)" on-swipe="cardswiped($index)"> <div class="list card mycard"> <!-- card header--> <div class="item topicdescription cardheader"> <p>{{card.topicdescription}}</p> </div> <!-- card body--> <div class="item item-body noborder"> <img class="full-image" src="{{card.image}}"> <h3 class="cardtitle">{{card.title}}</h3> <p>{{card.summary}}</p> </div> <!-- card footer--> <div class="item tabs tabs-secondary tabs-icon-left cardfooter"> <a class="tab-item" ng-click="readmore($index)" href="#"> <i class="{{card.actionbuttonicon}}"></i> {{card.actionbuttontext}} {{card.type}} ( {{card.additionalinfo}} ) </a> <a class="tab-item" ng-click="share($index)" href="#"> <i class="icon ion-share"></i> share </a> </div> </div> </td-card> </td-cards>
json file:
{ "articles": [ { "id":1, "topicdescription": "find idea", "image": "img/uber.jpg", "title": "uber lowers fares in on 100 cities", "summary": "uber lowering prices in on 100 u.s. , canadian cities, effective tomorrow. january slower month car service , company says reducing fares in order increase demand.", "link": "http://techcrunch.com/2016/01/08/uber-lowers-fares-in-over-100-cities/", "actionbuttonicon": "icon ion-ios-glasses-outline", "actionbuttontext": "read", "type":"article", "additionalinfo": "3 min" }, { "id":2, "topicdescription": "test idea", "image": "img/lean.jpg", "title": "the lean startup", "summary": "great book startups , how validate idea without spending money , time.", "link": "http://www.amazon.de/lean-startup-innovation-successful-businesses/dp/0670921602/ref=sr_1_2?ie=utf8&qid=1452779528&sr=8-2&keywords=the+lean+startup", "actionbuttonicon": "icon ion-ios-bookmarks-outline", "actionbuttontext": "buy", "type":"book", "additionalinfo": "amazon" }, { "id":3, "topicdescription": "build", "image": "img/evernote.jpg", "title": "note taking app", "summary": "from short lists lengthy research, no matter form writing takes, evernote keeps focused on moving ideas inspiration completion.", "link": "https://evernote.com/?var=3", "actionbuttonicon": "icon ion-hammer", "actionbuttontext": "download", "type":"app", "additionalinfo": "app store" }, { "id":4, "topicdescription": "measure", "image": "img/steve.jpg", "title": "steve blank: how build great company", "summary": "join silicon valley serial entrepreneur-turned-educator blank in lively discussion dan'l lewin of microsoft. program introduce best practices, lessons , tips have swept startup world, offering wealth of proven advice , information entrepreneurs of stripes.", "link": "https://www.youtube.com/watch?v=1rtcxwjucau", "actionbuttonicon": "icon ion-ios-videocam-outline", "actionbuttontext": "watch", "type":"video", "additionalinfo": "youtube" }, { "id":5, "topicdescription": "find idea", "image": "img/uber.jpg", "title": "uber lowers fares in on 100 cities", "summary": "uber lowering prices in on 100 u.s. , canadian cities, effective tomorrow. january slower month car service , company says reducing fares in order increase demand.", "link": "http://techcrunch.com/2016/01/08/uber-lowers-fares-in-over-100-cities/", "actionbuttonicon": "icon ion-ios-glasses-outline", "actionbuttontext": "read", "type":"article", "additionalinfo": "3 min" }, { "id":6, "topicdescription": "test idea", "image": "img/lean.jpg", "title": "the lean startup", "summary": "great book startups , how validate idea without spending money , time.", "link": "http://www.amazon.de/lean-startup-innovation-successful-businesses/dp/0670921602/ref=sr_1_2?ie=utf8&qid=1452779528&sr=8-2&keywords=the+lean+startup", "actionbuttonicon": "icon ion-ios-bookmarks-outline", "actionbuttontext": "buy", "type":"book", "additionalinfo": "amazon" }, { "id":7, "topicdescription": "build", "image": "img/evernote.jpg", "title": "note taking app", "summary": "from short lists lengthy research, no matter form writing takes, evernote keeps focused on moving ideas inspiration completion.", "link": "https://evernote.com/?var=3", "actionbuttonicon": "icon ion-hammer", "actionbuttontext": "download", "type":"app", "additionalinfo": "app store" }, { "id":8, "topicdescription": "measure", "image": "img/steve.jpg", "title": "steve blank: how build great company", "summary": "join silicon valley serial entrepreneur-turned-educator blank in lively discussion dan'l lewin of microsoft. program introduce best practices, lessons , tips have swept startup world, offering wealth of proven advice , information entrepreneurs of stripes.", "link": "https://www.youtube.com/watch?v=1rtcxwjucau", "actionbuttonicon": "icon ion-ios-videocam-outline", "actionbuttontext": "watch", "type":"video", "additionalinfo": "youtube" } ] }
i examined code. in controllers.js file handle cardswiped event manually adding undefined card list
$scope.cardswiped = function(index) { var newcard = // new card data $scope.cards.push(newcard); };
this causes cards have multiple undefined elements ng-repeat forced handle duplicates. remove/fix handler , things should work.
btw, code work because javascript handle them single line var newcard = $scope.cards.push(newcard);
means @ end of function newcard variable have new length of cards array.
Comments
Post a Comment