Paste html content as plain text into a contenteditable div using AngularJs

I want to insert text selected from a specific document (pdf, docx, html) into a div of type contenteditable.

Now I want to remove all clipboard text formatting before being rendered . Thus, the final content of the inserted text should be plain text.

An analogue of this scenario may be pasting content into Windows Notepad.

How can this be done using AngularJs. Or is there any other javascript library to execute this.

Update: I can use the following code to get the clipboard as text.

editor.addEventListener("paste", function(e) { // cancel paste e.preventDefault(); // get text representation of clipboard var text = e.clipboardData.getData("text/plain"); // insert text manually document.execCommand("insertHTML", false, text); }); 

But I do not know how and where to add this code in AngularJs.

+8
javascript html angularjs contenteditable plaintext
source share
1 answer

Check this answer, you can capture insert events. It doesn't matter if it contains the contents of an editable div or otherwise.

JavaScript gets clipboard data on paste (cross browser)

0
source share

All Articles