Skip to content

Instantly share code, notes, and snippets.

@changhuixu
Created March 24, 2019 03:31
Show Gist options
  • Save changhuixu/3598dac2aff06e82e92293de48392df5 to your computer and use it in GitHub Desktop.
Save changhuixu/3598dac2aff06e82e92293de48392df5 to your computer and use it in GitHub Desktop.
Lazy Load External JavaScript Library in Angular
declare var Quill: any;
@Component({
//...
})
export class QuillEditorComponent implements OnInit {
constructor(
// ...
private readonly svc: QuillEditorService,
@Inject(DOCUMENT) private readonly document: any
) {}
ngOnInit() {
this.svc.lazyLoadQuill().subscribe(_ => {
if (!Quill) {
Quill = this.document.defaultView.Quill;
}
this.setupQuill();
});
}
setupQuill() {
if (!Quill) {
return;
}
// set up External JS library
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment