ngx-timeago icon indicating copy to clipboard operation
ngx-timeago copied to clipboard

Add ngZone.runOutsideAngular

Open hoancmg opened this issue 4 years ago • 4 comments

Add an ngZone exclusion to prevent the macro task running in the background. Need this update to help Protractor (e2e test) not hang indefinitely.

hoancmg avatar Apr 15 '20 17:04 hoancmg

would be really nice to have it merged

mpashkovskiy avatar May 31 '20 09:05 mpashkovskiy

While the PR is open, limited/dirty workaround would be to implement wrapper like that:

import { ChangeDetectorRef, NgZone, Pipe, PipeTransform } from '@angular/core';
import { TimeagoDefaultClock, TimeagoDefaultFormatter, TimeagoIntl, TimeagoPipe } from 'ngx-timeago';

@Pipe({
  name: 'timeagoWrapper',
})
export class TimeagoWrapperPipe implements PipeTransform {

  private timeago: TimeagoPipe;

  constructor(private cd: ChangeDetectorRef, private ngZone: NgZone) {
    this.timeago = new TimeagoPipe(
      new TimeagoIntl(),
      this.cd,
      new TimeagoDefaultFormatter(),
      new TimeagoDefaultClock()
    );
  }

  transform(value: any, ...args: any[]): any {
    return this.ngZone.runOutsideAngular(() => this.timeago.transform(value));
  }

}

mpashkovskiy avatar Jun 01 '20 06:06 mpashkovskiy

@hoancmg can you fix the tests and use angular commit message guidelines? I will merge it afterwards.

ihym avatar Jun 01 '20 07:06 ihym

This is a great library, but unusable for me (and I'm sure many others) until it is compatible with protractor testing.

conor-mac-aoidh avatar Mar 25 '21 14:03 conor-mac-aoidh