sachinchoolur / angular-trix

A rich WYSIWYG text editor directive for angularjs.
http://sachinchoolur.github.io/angular-trix/
MIT License
328 stars 62 forks source link

HTML contains stray <!--block--> due to binding approach #14

Open cms103 opened 8 years ago

cms103 commented 8 years ago

The library currently takes the HTML of the editor and binds it to the Angular variable. This results in some internal Trix HTML comments being added to the HTML (<!--block--> - see below). A better way is to use Trix to serialize the editor state into HTML:

Replace: ngModel.$setViewValue(element.html()); with ngModel.$setViewValue(Trix.serializeToContentType(element[0], "text/html"))

The HTML output changes from this:

<div><!--block-->Test<br><br>Now works correctly!<br><br><strong>Bold</strong> and <em>great</em> once again.<br><br><strong><br></strong><br></div>

to the nicer:

<div>Test<br><br>Now works correctly!<br><br><strong>Bold</strong> and <em>great</em> once again.<br><br><strong><br></strong><br></div>

chinnaprince commented 7 years ago

I am new using to angular trix. I am having some trouble in retrieving the data from the database. As shown above when I save the content from the editor to database it is saving fine but when I retrieve instead of the data what I saved, HTML tags are applying.

For example: in the editor if save Sample content as bold and when I reload the page after saving it is displayed as < div >< strong>Sample content< /strong>< /div> but I just need Sample content in bold. Please help me in fixing this issue.

ghost commented 7 years ago

See this: https://github.com/basecamp/trix/issues/249 In other words you are supposed to use val() instead of html() in trix-change @sachinchoolur please fix