Skip to content

Commit

Permalink
fix(ngx-codejar): cannot set style of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed Dec 12, 2023
1 parent c9304b0 commit f8facb7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libs/ngx-codejar/src/lib/ngx-code-jar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
Renderer2,
SimpleChanges,
Expand All @@ -22,14 +21,14 @@ import {CommonModule} from '@angular/common';
imports: [CommonModule],
selector: 'ngx-codejar',
template: `
<div class="ngx-codejar-wrap ngx-codejar-flex" #wrapper>
<div class="ngx-codejar-wrap ngx-codejar-flex" #wrapper>
<pre #editor class="editor" [ngClass]="{
'hljs': highlighter === 'hljs',
'language-typescript': highlighter === 'prism',
'ngx-codejar-editor': highlighter !== undefined
}" style="padding-bottom:0px;">
</pre>
</div>`,
</div>`,
styles: [`
:host {
display: block;
Expand Down Expand Up @@ -216,14 +215,18 @@ export class NgxCodeJarComponent implements AfterViewInit, OnChanges, OnDestroy
}

private applyCustomizations() {
if (this.wrapper && this.editor) {
if (this.wrapper && this.editor && this.el?.nativeElement) {
const codejarWrap = (this.wrapper.nativeElement as HTMLElement).firstElementChild;
const lineNumbers = this.el.nativeElement.getElementsByClassName('codejar-linenumbers')[0];

this.renderer.setStyle(codejarWrap, 'height', '100%');
if (codejarWrap) {
this.renderer.setStyle(codejarWrap, 'height', '100%');
}

if (this.el.nativeElement.style.height !== '') {
this.renderer.setStyle(lineNumbers, 'height', '100%');
if (lineNumbers) {
if (this.el.nativeElement.style?.height) {
this.renderer.setStyle(lineNumbers, 'height', '100%');
}
}
}
}
Expand Down

0 comments on commit f8facb7

Please sign in to comment.