From 6d7a903424e49c96102bb7342ceb788c64ed211f Mon Sep 17 00:00:00 2001 From: kuuurt13 Date: Thu, 30 Jan 2020 19:25:01 -0500 Subject: [PATCH] fix(Directive): Added ivy renderer support --- lib/directives/block-ui.directive.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/directives/block-ui.directive.ts b/lib/directives/block-ui.directive.ts index d76ce2f..59f1194 100644 --- a/lib/directives/block-ui.directive.ts +++ b/lib/directives/block-ui.directive.ts @@ -47,7 +47,11 @@ export class BlockUIDirective implements OnInit { ngOnInit() { try { this.viewRef.createEmbeddedView(this.templateRef); - const parentElement = this.viewRef.element.nativeElement.nextSibling; + const { + nextSibling, + previousSibling + } = this.viewRef.element.nativeElement; + const parentElement = nextSibling || previousSibling; if (parentElement && !this.isComponentInTemplate(parentElement)) { this.renderer.addClass(parentElement, 'block-ui__element'); @@ -82,8 +86,15 @@ export class BlockUIDirective implements OnInit { // Needed for IE (#17) private findContentNode(element: any) { - const { nextSibling } = element; - return [nextSibling, nextSibling.nextSibling].find((e) => e.localName === 'block-ui-content'); + const nextSibling = element.nextSibling || {}; + const previousSibling = element.previousSibling || {}; + + return [ + nextSibling, + nextSibling.nextSibling, + previousSibling, + previousSibling.previousSibling + ].find((e) => e && e.localName === 'block-ui-content'); } private createComponent() {