我正在使用离子2
这是我的代码:
<div class="messagesholder"
*ngFor="let chat of chatval | orderby:'[date]'; let i = index;let first=first;let last = last;">
{{last ? callFunction() : ''}}
<div *ngIf="chat.sender == currentuser || chat.receiver == currentuser" >
{{checkdate(chat.date)}}
<p class="chat-date" id="abc" #abc>{{msgdate | amDateFormat:'LL'}}</p>
</div>
这是我的checkdate
函数:
checkdate(date)
{
var res = date.split(" ");
var A=res[0];
var local=localStorage.getItem('chatdate');
this.msgdate="";
if(local === undefined || local === null)
{
this.msgdate=A;
localStorage.setItem('chatdate',this.msgdate);
}
else if(local !== undefined)
{
console.log(local != A);
if(local != A)
{
this.msgdate = A;
localStorage.setItem('chatdate',this.msgdate);
}
}
}
callFunction(){
this.content.scrollToBottom(0)
}
这是工作。但是我遇到了这个错误。
FIREBASE WARNING: Exception was thrown by user callback. Error: Expression has changed after it was checked. Previous value: 'April 10, 2017'. Current value: ''.
因为我通过在代码中使用这些行来工作:
import { Component, ChangeDetectionStrategy } from '@angular/core';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'page-chat',
templateUrl: 'chat.html',
})
现在。我没有错误的消息。但是内容不显示。
我安慰了chatval.it的wrk罚款。但它不显示任何值。
同时,当我去Backputton时,内容为显示。
如果我删除ChangeDetectionStrategy
,
再次获得此err msg
FIREBASE WARNING: Exception was thrown by user callback. Error: Expression has changed after it was checked. Previous value: 'April 10, 2017'. Current value: ''.
为什么使用ChangeDetectionStrategy
?UI值未显示。
认真地,您正在修改模型的状态。如果不绑定变量,您不应该这样做。删除
this.msgdate="";