usman usman - 3 months ago 20
AngularJS Question

How to bind a $scope variable with text editor in angularjs

This is my Editor input tag:

<textarea cols="18" rows="40" class="wysihtml5 wysihtml5-min form-control" ng-model="TemplateDescription"></textarea>


When binding my $scope variable with ng-model then it returns undefined. and when I bind my $scope variable with ng-bind-html then still the same result. So then I gave an Id to this textarea and accessed the value inside of it by using this statement.

$scope.TemplateDescription = $sce.trustAsHtml($("#templateDescription").val());


I get the values as shown in the image below, so how can I get my required html text in my modal so that I can pass this value to save into database. Any kind of help will be appreciated.
enter image description here

Answer

If your TemplateDescription variable is containing raw HTML then you can try something like this.

First you need to set your raw HTML as trusted.

$scope.TemplateDescription = $sce.trustAsHtml($scope.TemplateDescription);

And then you need to bind TemplateDescription using ng-model

<textarea cols="18" rows="40" class="wysihtml5 wysihtml5-min form-control" ng-model="TemplateDescription"></textarea>

I have tested it. It will work.