I would like to wrap the selected text in div paragram which with a custom component.
I know we can wrap text in <span>
, <b>
, etc. tag using :
let selection = window.getSelection();
let range = selection?.getRangeAt(0);
let selectedText = selection?.toString();
range.insertNode(document.createTextNode(`<span>${selectedText}</span>`));
But how to wrap in a custom component of angular?
Let's say we have a component SpecialComponent
with the selector as <app-special>
So DOM should be something like :
Lorem Ipsum has been the
<app-special>
industry's standard dummy text ever since</app-special>
the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
<app-comp1>some <app-comp2>more</app-comp2> text</app-comp1>
. Is that what you're looking for? – Brandon