Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TimeAgo pipe does not work with SSR #43

Open
tskweres opened this issue Jul 3, 2020 · 2 comments
Open

TimeAgo pipe does not work with SSR #43

tskweres opened this issue Jul 3, 2020 · 2 comments

Comments

@tskweres
Copy link

tskweres commented Jul 3, 2020

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

@flogh
Copy link

flogh commented Jan 28, 2021

+1

@zbigniewmotyka
Copy link

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,
  },
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants