Created
March 24, 2019 03:31
-
-
Save changhuixu/3598dac2aff06e82e92293de48392df5 to your computer and use it in GitHub Desktop.
Lazy Load External JavaScript Library in Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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