简体   繁体   中英

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. 在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM