Skip to content

Commit

Permalink
Fix Angular Universal error thrown in ngOnChanges, closes #243
Browse files Browse the repository at this point in the history
  • Loading branch information
MurhafSousli committed Jan 31, 2023
1 parent 4a74d84 commit 8815a9e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/ngx-highlightjs/src/lib/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
Inject,
Optional,
EventEmitter,
PLATFORM_ID,
OnChanges,
SimpleChanges,
ElementRef,
SecurityContext
} from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { DomSanitizer } from '@angular/platform-browser';
import { animationFrameScheduler } from 'rxjs';
import { HighlightJS } from './highlight.service';
Expand Down Expand Up @@ -46,12 +48,14 @@ export class Highlight implements OnChanges {
constructor(el: ElementRef,
private _hljs: HighlightJS,
private _sanitizer: DomSanitizer,
@Inject(PLATFORM_ID) private platformId: object,
@Optional() @Inject(HIGHLIGHT_OPTIONS) private _options: HighlightOptions) {
this._nativeElement = el.nativeElement;
}

ngOnChanges(changes: SimpleChanges) {
if (
isPlatformBrowser(this.platformId) &&
changes?.code?.currentValue !== null &&
changes.code.currentValue !== changes.code.previousValue
) {
Expand Down

0 comments on commit 8815a9e

Please sign in to comment.