admin管理员组

文章数量:1355670

I need to render HTML values in text area SUBMIT FORM. I can bind the html values in a <div> but not in a <textarea>. Also, ng-model for data binding can retrieve the value but it is displayed as html.

Controller

//task.descr contains "<br>-------<br><a href=""..."
var str="<br><hr><br>"+ task.descr;
//str= $sce.trustAsHtml(str);
$scope.formData5 = {
    descr: str}
console.log($scope.formData5);


<textarea placeholder="Deskripsi Memo"  name="descr" 
ngMaxlength="1000" ng-model="formData5.descr" 
ng-bind-html="formData5.descr" > </textarea>

I need to render HTML values in text area SUBMIT FORM. I can bind the html values in a <div> but not in a <textarea>. Also, ng-model for data binding can retrieve the value but it is displayed as html.

Controller

//task.descr contains "<br>-------<br><a href="http://www.google."..."
var str="<br><hr><br>"+ task.descr;
//str= $sce.trustAsHtml(str);
$scope.formData5 = {
    descr: str}
console.log($scope.formData5);


<textarea placeholder="Deskripsi Memo"  name="descr" 
ngMaxlength="1000" ng-model="formData5.descr" 
ng-bind-html="formData5.descr" > </textarea>
Share Improve this question edited May 11, 2015 at 15:11 scniro 17k8 gold badges66 silver badges107 bronze badges asked Mar 7, 2015 at 4:08 xyonmexyonme 4051 gold badge8 silver badges24 bronze badges 3
  • Can't markup in textarea – reptilicus Commented Mar 7, 2015 at 4:19
  • if not using text area,what is the best way to render the HTML values as well as for ng-model? – xyonme Commented Mar 7, 2015 at 4:24
  • 1 use contenteditable for the div and achieve the same result :) – mohamedrias Commented Mar 7, 2015 at 4:48
Add a ment  | 

1 Answer 1

Reset to default 5

This would allow you have both two way data binding as well as give you the functionality of textarea:

  <div ng-bind-html="modelname"
         contenteditable="true"
         ng-model="modelname">
    </div>

DEMO

本文标签: javascriptAngularJS Render HTML in textareaStack Overflow