Created
May 14, 2021 11:55
-
-
Save lydemann/6933e72999b626aec8e4f674d5d6c9f3 to your computer and use it in GitHub Desktop.
course.component.ts
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
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