I'm using Renderer2 to render some custom elements in an Angular application. As each element is created, it is stored as a constant:
const myNewElement = this.renderer2.createElement('div');
When the time comes to remove this element, I am using removeChild. This has a parameter for the parent
of the node being removed:
removeChild(parent: any, oldChild: any, isHostElement?: boolean | undefined)
However if I set parent
to null, it seems to remove oldChild
from the DOM successfully and without throwing an error:
this.renderer2.removeChild(null, myNewElement); // Works!
Could this approach cause any potential issues? Should a parent element be specified, even if removeChild
works without it?