Reputation: 1621
<ion-item
class="item-icon-left item-icon-right item-avatar"
ng-repeat="note in taskDetails.notes track by note.note_id"
ng-click="viewNote(note)">
<i ng-show="note.status.name==Open" class="icon ion-ios-circle-outline"></i>
<i ng-show="note.status.name!=Open"class="icon ion-ios-checkmark-outline"></i>
<h2>{{note.note}}</h2>
<p>{{note.created_by}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
Task Object
{"task_date_id":69069,"task_id":"3286","start_time":"2018-02-22 12:10:00","end_time":"2018-02-22 12:10:00","overdue_days":0,"subject":"Oneone","description":"One","status":{"id":3,"name":"Pending","enabled":null,"complete":null},"statuses":[{"id":3,"name":"Pending"},{"id":6,"name":"Assigned"},{"id":4,"name":"Closed"},{"id":17,"name":"Complete"}],"type":{"id":229,"name":"200_Test_Mobile_Task"},"assigned_to":"Kanishka Raveendra","address":"","clients":[],"attachments":[],"notes":[],"$$hashKey":"object:8112"}
Note Object
{"note_id":"98834","note_date":"22/02/2018","note_type":"ABC14","time_spent":0,"note":"Xyxhxffuf\n
{$PERSON_FIRST_NAME} {$PERSON_SURNAME}
","created_by":"Kanishka Raveendra","date_created":"","attachments":[],"template":"{$PERSON_FIRST_NAME} {$PERSON_SURNAME}
","type":{"id":52,"name":"ABC14","enabled":true,"record_time":"start_stop"}}
here I added source code and response of Task and Note which I used to show the data.Normally one task can have a number of notes.But Here clearly we can see notes array has no elements.But I can see some notes objects from others tasks in the View.I need to show correct values of notes in View.please help me.I'm new to ionic.
Console error
Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: note in taskDetails.notes track by note.note_id, Duplicate key: 98834, Duplicate value: {"note_id":"98834","note_date":"22/02/2018","note_type":"ABC14","time_spent":0,"note":"Xyxhxffuf\n
{$PERSON_FIRST_NAME} {$PERSON_SURNAME}
","created_by":"Kanishka Raveendra","date_created":"","attachments":[],"template":"{$PERSON_FIRST_NAME} {$PERSON_SURNAME}
","type":{"id":52,"name":"ABC14","enabled":true,"record_time":"start_stop"}}
Upvotes: 1
Views: 84
Reputation: 6053
In your track by note.note_id
getting the same value.
Use $index
which is iterator offset of the repeated element (0..length-1) in ng-repeat
.
Please check for more details from here.
Use the following solution :
<ion-item
class="item-icon-left item-icon-right item-avatar"
ng-repeat="note in taskDetails.notes track by $index"
ng-click="viewNote(note)">
<i class="icon" ng-class="{'ion-ios-circle-outline': note.status.name === 'Open', 'ion-ios-checkmark-outline': note.status.name !== 'Open'}"></i>
<h2>{{note.note}}</h2>
<p>{{note.created_by}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
Hope this will help you !!
Upvotes: 2
Reputation:
try this
<ion-item
class="item-icon-left item-icon-right item-avatar"
ng-repeat="(key, value) in taskDetails.notes track by $index"
ng-click="viewNote(note)">
......
</ion-item>
Upvotes: 1