Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created May 14, 2021 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydemann/6933e72999b626aec8e4f674d5d6c9f3 to your computer and use it in GitHub Desktop.
Save lydemann/6933e72999b626aec8e4f674d5d6c9f3 to your computer and use it in GitHub Desktop.
course.component.ts
ngOnDestroy(): void {
this.renderer.removeChild(this.elementRef.nativeElement, this.styleElement);
this.destroy$.next();
this.destroy$.complete();
}
ngOnInit() {
switchMap((courseId) =>
this.courseFacade.getCourseCustomStyling(courseId)
)
);
this.courseCustomStyle$
.pipe(
takeUntil(this.destroy$),
filter((style) => !!style)
)
.subscribe((style) => {
const sanitizedStyle = this.sanitizer.sanitize(
SecurityContext.STYLE,
style
);
this.createStyle(sanitizedStyle);
});
}
private createStyle(style: string): void {
this.styleElement = this.renderer.createElement('style');
this.renderer.appendChild(
this.styleElement,
document.createTextNode(style)
);
this.renderer.appendChild(this.elementRef.nativeElement, this.styleElement);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment