我正在使用离子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'.
我该如何解决这个问题......
请建议我,
由于
答案 0 :(得分:0)
您收到以下错误,因为您正在尝试修改在循环语句中执行后端处理的对象。
Error in ./ChatPage class ChatPage - caused by: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.
如果您想获得唯一日期,那么您可以尝试以下示例,它将为您提供来自您的收藏集的唯一chatDate:
let Values = this.chatval.map(function (item) { return item["date"]; }).filter(this.OnlyUnique);
OnlyUnique(value, index, self): any {
return self.indexOf(value) === index;
}