How is styling being applied on selected characters of the string- AngularJS

微笑、不失礼 提交于 2019-12-11 18:37:00

问题


I came across rich text editor in this plunkr and wanted to know how exactly is the code able to understand that a particular element has to be decorated with bold styling ?

The $container.html() shows proper styling in console but how it knows which part of string was selected for styling ?


回答1:


So that plunkr is using a HTML5 feature called contenteditable. In short this attribute turns a html element (usually a div) into something that can act like a textarea, but you're editing the actual html on the page. As for the selected styling the Bold button is using Document.execCommand to apply a command to the current selection.

Here's a tutorial on getting started with contenteditable and execCommand: https://code.tutsplus.com/tutorials/create-a-wysiwyg-editor-with-the-contenteditable-attribute--cms-25657. Hope that helps.

PS I updated the link in the other question you commented on.



来源:https://stackoverflow.com/questions/49773118/how-is-styling-being-applied-on-selected-characters-of-the-string-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!