简体   繁体   English

如何在angularjs中使用文本编辑器绑定$ scope变量

[英]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 . 将我的$ scope变量与ng-model绑定时,它将返回undefined and when I bind my $scope variable with ng-bind-html then still the same result. 当我将我的$ scope变量与ng-bind-html绑定时,结果仍然相同。 So then I gave an Id to this textarea and accessed the value inside of it by using this statement. 因此,我给了该文本区域一个ID,并使用此语句访问了其中的值。

$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. 我得到的值如下图所示,所以如何在模态中获取所需的html文本,以便可以将此值传递到数据库中。 Any kind of help will be appreciated. 任何帮助将不胜感激。 在此处输入图片说明

If your TemplateDescription variable is containing raw HTML then you can try something like this. 如果您的TemplateDescription变量包含原始HTML,则可以尝试类似的操作。

First you need to set your raw HTML as trusted. 首先,您需要将原始HTML设置为可信。

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

And then you need to bind TemplateDescription using ng-model 然后您需要使用ng-model绑定TemplateDescription

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

I have tested it. 我已经测试过了 It will work. 它会工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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