sampotts / plyr

A simple HTML5, YouTube and Vimeo player
https://plyr.io
MIT License
26.54k stars 2.93k forks source link

Angular Universal #1443

Open Tatenda opened 5 years ago

Tatenda commented 5 years ago

I am trying to use this plugin in an app which uses Angular Universal. However it tells me document is not defined (which is expected). I would like to request a fix to this issue.

sampotts commented 5 years ago

The fastest way is to take a look yourself and create a pull request 👍

agarciar commented 1 year ago

Hi, a possible solution in Angular Universal is to use dynamic imports:

if (isPlatformBrowser(this.platformId)){
  import('plyr').then(
    (plyr) => (this.plyr = new plyr.default(this.elementRef.nativeElement))
  );
}

This code will make Plyr available only in the browser, while ensuring that Angular Universal works correctly.