angular2 SimpleChange未存储'previousValue'`

angular2 SimpleChange未存储'previousValue'`,angular,Angular,这是以下方面的后续行动: 我将ionic2/angular2与此组件一起使用:以及以下标记 <ion-card class="timer" *ngFor="let snapshot of timers | toJSON" > <ion-card-content> <round-progress [current]="snapshot.remaining" [max]="snapshot.duration"

这是以下方面的后续行动:

我将
ionic2
/
angular2
与此组件一起使用:以及以下标记

<ion-card  class="timer"
  *ngFor="let snapshot of timers | toJSON"
> 
  <ion-card-content>
    <round-progress 
      [current]="snapshot.remaining" 
      [max]="snapshot.duration"
      [rounded]="true"
      [responsive]="true"
      [duration]="18"
      >
    </round-progress>
</ion-card>
为什么我没有正确存储
更改.current.previousValue

toJSON
管道调用此方法,该方法返回一个匿名对象:

  /**
   * create a snapshot of the timer
   */
  toJSON() : TimerAttributes {
    const remaining = this.check(true);
    console.log(this.id, this.duration, remaining)
    return {
      id: this.id,
      label: this.label,
      // asMilliseconds
      duration: this.duration,
      // asMilliseconds
      remaining: remaining,
      humanize: this.humanize(remaining),
      // as Unixtime
      expires: this.expires
    }
  } 

我唯一的猜测是,在每个更改检测循环中,我为快照返回了不同的对象,因此我丢失了以前的值。但是如果是这样,那么什么是容易解决的问题呢?

如果
@Input
变量的对象发生更改

  /**
   * create a snapshot of the timer, return as anonymous object
   */
  toJSON() : TimerAttributes {
    const remaining = this.check();
    // console.log(this.id, this.duration, remaining)
    return {
      id: this.id,
      label: this.label,
      // asMilliseconds
      duration: this.duration,
      // asMilliseconds
      remaining: remaining,
      humanize: this.humanize(remaining),
      // as Unixtime
      expires: this.expires
    }
  }


  /**
   * return the SAME object with updated attr value 
   */
  snap(): TimerAttributes {
    Object.assign( this.snapshot, this.toJSON())
    return this.snapshot;
  }
如果我的
toJSONPipe
调用
o.toJSON()
我会得到一个带有属性值的匿名对象,并且
SimpleChange
不会存储
更改.current.previousValue


如果我的
toJSONPipe
调用
o.snap()
我将获得具有更新属性值的相同属性
o.snapshot
,并且
SimpleChange
正确存储
更改.current.previousValue

我的猜测是正确的。如果我使用
Object.assign(snapshot,o.toJSON())
,那么
snapshot
引用同一个对象并且
SimpleChange.previousValue
正确地保存了
快照的previousValue。剩余的
。但是,在检查
错误后,我有可能得到一个
表达式已更改。解决办法是什么?
  /**
   * create a snapshot of the timer, return as anonymous object
   */
  toJSON() : TimerAttributes {
    const remaining = this.check();
    // console.log(this.id, this.duration, remaining)
    return {
      id: this.id,
      label: this.label,
      // asMilliseconds
      duration: this.duration,
      // asMilliseconds
      remaining: remaining,
      humanize: this.humanize(remaining),
      // as Unixtime
      expires: this.expires
    }
  }


  /**
   * return the SAME object with updated attr value 
   */
  snap(): TimerAttributes {
    Object.assign( this.snapshot, this.toJSON())
    return this.snapshot;
  }