Hi All,
I am getting the following error, what is the best way that I should handle it?
ORIGINAL EXCEPTION: Expression has changed after it was checked. Previous value: '3m 18s'. Current value: '3m 19s'
I have a list iterating and for each object it calls a function to calculate the time last online. This works perfectly, but I have noticed each time there is screen activity it calls the function again, and updated the displayed time (pretty cool in that the time updates). Eventually it gets the above error.
html
<ion-list> <ion-item-sliding *ngFor="let result of employeeModels"> <ion-item> {{ formatEmployee(result) }} <ion-avatar item-left><img [src]="result.avatar64 ? result.avatar64 : 'images/blank-profile-picture.png'"></ion-avatar> <h2>{{result.firstName}}</h2> <p>{{result.categories[0].name}} {{result.subCategories[0].name}} {{result.time}}</p> </ion-item> <ion-item-options> <button primary> <ion-icon name="text"></ion-icon> Message </button> </ion-item-options> </ion-item-sliding> </ion-list>
script
formatEmployee(employeeModel: Employee) {
if (employeeModel.avatar) {
employeeModel.avatar64 = decodeURIComponent(window.atob(employeeModel.avatar));
}
this.lastAccessDate(employeeModel);
}
lastAccessDate(employeeModel: Employee) {
//console.log(employeeModel.id+β: β+new Date().getTime()+β - β+employeeModel.lastAccessDate+β = (β+(new Date().getTime()-employeeModel.lastAccessDate)+β)β);
employeeModel.time = this.displayTime(employeeModel.lastAccessDate);
}
displayTime(lastAccessDate: number) {
var now: number = new Date().getTime();
var timeDiff: number = now - lastAccessDate;
timeDiff /= 1000;
var seconds = Math.round(timeDiff % 60);
timeDiff = Math.floor(timeDiff / 60);
var minutes = Math.round(timeDiff % 60);
timeDiff = Math.floor(timeDiff / 60);
var hours = Math.round(timeDiff % 24);
timeDiff = Math.floor(timeDiff / 24);
var days = Math.round(timeDiff % 7);
timeDiff = Math.floor(timeDiff / 7);
var weeks = timeDiff;
var returnString = weeks + "w " + days + "d"; if (weeks <= 0) { returnString = days + "d " + hours + "h"; if (days <= 0) { returnString = hours + "h " + minutes + "m"; if (hours <= 0) { returnString = minutes + "m " + seconds + "s"; if (minutes <= 0) { returnString = seconds + "s"; } } } }
return returnString;
}