diff --git a/src/app/components/contextmenu/contextmenu.ts b/src/app/components/contextmenu/contextmenu.ts index 0b593c9e55a..445e60d9240 100755 --- a/src/app/components/contextmenu/contextmenu.ts +++ b/src/app/components/contextmenu/contextmenu.ts @@ -1150,8 +1150,13 @@ export class ContextMenu implements OnInit, AfterContentInit, OnDestroy { removeAppendedElements() { if (this.appendTo) { - if (this.appendTo === 'body') this.renderer.removeChild(this.document.body, this.containerViewChild.nativeElement); - else DomHandler.removeChild(this.containerViewChild.nativeElement, this.appendTo); + if (this.appendTo === 'body') { + if(this.containerViewChild) { + this.renderer.removeChild(this.document.body, this.containerViewChild.nativeElement); + } + } else { + DomHandler.removeChild(this.containerViewChild.nativeElement, this.appendTo); + } } }