You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(cdk Portal): Allow DomPortal to reference detached elements #34023
There is a built-in security that blocks a detached element (one that has no parent node) to be used in a DomPortal, here.
The only purpose of this bit of code is to ensure that if the DOM node is obtained the nominal way, i.e from the component's view, then it gets put back where it was before, when the operation is done or it stops being used.
Use Case
I have a dependency that generates DOM nodes (SVG nodes to be precise). I was using a custom directive that was using inject(ElementRef).nativeElement and .replaceChildren(this.inputDOMNode()), which works but is not great.
I discovered Portal and thought I could use it, but I actually can't because the built-in security prevents me from passing a detached element to DOMPortal(). I guess I could instanciate a dummy DOM node (itself detached) to attach all my SVG nodes to it before passing them to the DOMPortal, but that's nonsense really, I just don't need the housekeeping feature of placing the node back where it was found.
Activity