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

TimeAgo pipe does not work with SSR

Open tskweres opened this issue 4 years ago • 2 comments

Probably due to resolving an observable, but TimeAgo only works on the browser. If implemented with SSR, SSR hangs and the page never loads.

tskweres avatar Jul 03 '20 16:07 tskweres

+1

flogh avatar Jan 28 '21 08:01 flogh

I've prepared PR for this issue. As a workaround you can create following service:

import { isPlatformBrowser } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { TimeagoDefaultClock } from 'ngx-timeago';
import { EMPTY, Observable } from 'rxjs';

@Injectable({
  providedIn: 'root',
})
export class TimeagoAppClock extends TimeagoDefaultClock {
  constructor(
    @Inject(PLATFORM_ID) private readonly platformId: Record<string, unknown>
  ) {
    super();
  }

  tick(then: number): Observable<unknown> {
    return isPlatformBrowser(this.platformId) ? super.tick(then) : EMPTY;
  }
}

and use it instead of default clock:

TimeagoModule.forRoot({
  clock: {
    provide: TimeagoClock,
    useClass: TimeagoAppClock,
  },
}),

zbigniewmotyka avatar Oct 02 '21 19:10 zbigniewmotyka