Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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