1

I created a simple stopwatch pipe which should show me the seconds diff. after a certain date:

import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';

@Pipe({
  name: 'stopwatch',
  pure: false
})
export class StopwatchPipe implements PipeTransform {

  transform(value: Date, args?: any): any {
    return moment().diff(value);
  }

}

I made the pipe impure to permanently detect changes. I also found this thread but I'm not sure how to integrate the change detection in my pipe: How to manage Angular2 "expression has changed after it was checked" exception when a component property depends on current datetime

Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'null: 672162'. Current value: 'null: 672163'.

Question: How to properly return the time diff without having the above error?

Andi Giga
  • 3,744
  • 9
  • 38
  • 68

0 Answers0