我正在使用离子2
这是我的模板代码
<div class="messagesholder" *ngFor="let chat of chatval | orderby:'[date]'; let last = last">
{{last ? callFunction() : ''}}
<div *ngIf="chat.sender == currentuser || chat.receiver == currentuser">
<p *ngIf="msgdate === undefined" class="chat-date" #ChatDate id="ChatDate" >{{chat.date | amDateFormat:'LL'}}</p>
{{checkdate(chat.date)}}
</div>
<div class="message" *ngIf="chat.sender == currentuser || chat.receiver == currentuser" [ngClass]="{'me': currentuser == chat.sender}">
<div class='image' *ngIf="chat.path" >
<img *ngIf="chat.path" [src]="chat.path" imageViewer/><br>
<span *ngIf="chat.path_text">{{chat.path_text}}</span>
<span style="font-size:9px;">{{chat.date | amDateFormat:'hh:mmA'}}</span>
</div>
<div *ngIf="chat.message_text">
<span>{{chat.message_text}}</span>
<span style="font-size:9px;">{{chat.date | amDateFormat:'hh:mmA'}}</span>
</div>
</div>
</div>
这是我的函数
checkdate(i)
{
console.log("date");
console.log(i);
this.msgdate=i;
}
我需要相同的日期值不要重复。因为我使用这个函数{{checkdate(chat.date(}}获取输入元素值。
但是我得到了这个错误。
Error in ./ChatPage class ChatPage - caused by: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.
我该如何解决这个问题...
请告诉我,
谢谢
您收到以下错误,因为您正在尝试修改在循环语句中执行后端进程的对象。
Error in ./ChatPage class ChatPage - caused by: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.
如果您想获得唯一的日期,那么您可以尝试以下示例,它将为您提供集合中唯一的聊天日期:
let Values = this.chatval.map(function (item) { return item["date"]; }).filter(this.OnlyUnique);
OnlyUnique(value, index, self): any {
return self.indexOf(value) === index;
}