在 angular 中清除 trumbowyg 编辑器

Clearing the trumbowyg editor in angular

我目前使用的是trumbowyg editor on a project and I am having a problems clearing the contents of the editor. Every thing is fine if I want to re-populate the editor by changing the contents of the model attached to it but it will not clear the contents of the editor when I do $scope.editorModel = '';. I have a Plunker here,它解释得更多一些(单击页面底部的按钮)。

有人有什么想法吗?

就我个人而言,我认为它是一个相当缺乏的指令,但对于 jquery 插件的 angular 包装器,它往往很像这样。

问题当然是无法访问 trumbowyg 元素。 简单的方法是给元素一个 id,然后用 angular.element 来选择它。

<div trumbowyg-ng id="test" ...

$scope.trumbo = angular.element("#test");
$scope.trumbo.empty(); // (from the trumbowyg documentation)

肯定不是angular方式(tm)。我想更改指令并使 trumbowyg 对象以其他方式可用会更漂亮。抱歉偷懒了。

扩展 ippi 的答案我发现 divs 而不是 textareas 并且以下代码解决了我的情况:

<div trumbowyg-ng id="trumbowyg" ...

$scope.trumbo = angular.element("#trumbowyg");
$scope.trumbo['0'].textContent = '';

我发现 Trumbowyg (2.4.2) and trumbowyg-ng 的较新版本在模型上具有良好的 two-way 绑定。

所以,现在当模型直接设置为 '' 时,模型和 trumbowyg 编辑器都会空白。

<pre>editorModel: {{editorModel}}</pre>
<textarea trumbowyg-ng ng-model="editorModel"></textarea>

在此处查看工作中的内容: http://plnkr.co/edit/FoCUDI?p=preview