Search code examples
angularjstextangular

Checkboxes in text angular not saving


I'm using text-angular to save html-based content into database and i want to save checkboxes with the checked attribute on them. I've tried to use the input field like below but text-angular doesnt render checkboxes with checked attribute. Is there any way to do this without doing pure css checkboxes?

<input type="checkbox" checked>

EDIT: The code I am using:

<text-angular data-ng-model="example_content" placeholder="Content..." 
              rows="5">

And inside the textarea of the text-angular directive, I am trying to insert the input from above but it renders without checked attribute


Solution

  • I looked up in text-angular's sanitizer library textAngular-sanitize.js to find out that the checked attribute isn't part of their htmlAttrs attribute map.

    Hence, the only option we're left with is to override the sanitizer JS file with the edit. Moreover, you can add other attributes/tags if you want (Do consider vulnerabilities though!)

    Here's the working example plunker forked from official text-Angular plunker. Notice the ta-sanitize.js included in plunker which is modified version of their textAngular-sanitize.js

    Hope this helps!