Check value with previous value

nativescriptcore

#1

In a ListView i need to check if a date is different from the date of previous record

< ListView [items]="myItems" (itemTap)="onItemTap($event)" >
< ng-template let-item="item" >

item.data

< /ng-template >

< /ListView >

Anyone can help me?

Thank you


#2

You can use an index, passing to a function. And in it you take the previous index (index - 1), and validate with the new indece. Like this :

< ListView [items]="myItems" (itemTap)="onItemTap($event)" >
  < ng-template let-item="item"  let-indx="index">
    <Label [text]="checkDate(indx)"></Label>

  < /ng-template >
< /ListView >
checkDate(index){
  if(this.myItems[index] != this.myItems[index-1]){
    console.log("diff");
  }else{
    console.log('equals');
  }
}

#3

Excuse me, where i’ve tu put the checkdate function?
In which file?

thank you


#4

Are you using angular?


#5

If so, you put it inside the .ts file with the same name as your view, for example:

View: home.component.html

would put the function in the file: home.component.ts