Angular ChangeDetectionStrategy未正确工作
我用的是离子2 这是我的密码Angular ChangeDetectionStrategy未正确工作,angular,ionic2,angular2-changedetection,Angular,Ionic2,Angular2 Changedetection,我用的是离子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 || c
<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>
这是工作,但我得到了这个错误
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。它很好。但它没有显示任何价值
同时,当我转到backbutton.content时,将显示onesec
如果我删除ChangeDetectionStrategy
我又犯了这个错误
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="";
我还使用changedtectorref.markForCheck();但仍然不正确。错误只会消失,直到您找到另一种方法来更改变量,然后再由更改检测器进行检查。这就是为什么我建议绑定变量,这样一旦组件更改它,它就会得到模型的更新值。你能帮我吗。。。?
this.msgdate="";