TinyMCE setContent不会清除撤消历史记录

时间:2016-07-26 14:22:52

标签: javascript jquery html angularjs tinymce

我在表单中使用angular tinyMCE指令。提交后我使用此命令清除textarea:

tinyMCE.activeEditor.setContent('');

还有:$scope.tinymceModel ='';清除模型。我的表格是一个模态。当我再次打开模态时,textarea似乎很清楚,但TinyMCE中的“撤消”按钮是活动的,如果我点击它,我可以看到旧的内容。是否可以重置并清除TinyMCE撤消历史记录?这是html部分:

<textarea id="elm1" ui-tinymce="tinymceOptions" ng-model="tinymceModel" auto-focus id="elm1" rows="8" cols="100"></textarea>

这是选项

$scope.tinymceModel = '';
        $scope.tinymceOptions = {
            height: 420,
            language:'it',
            theme: "modern",
            plugins: [
                "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
                "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
                "save table contextmenu directionality emoticons template paste textcolor"
            ],
            content_css: "css/partials/content.css",
            toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | print preview media fullpage",
            style_formats: [
                {title: 'Bold text', inline: 'b'},
                {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
                {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
                {title: 'Example 1', inline: 'span', classes: 'example1'},
                {title: 'Example 2', inline: 'span', classes: 'example2'},
                {title: 'Table styles'},
                {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
            ],
            setup : function(ed){
                ed.on('keyup', function(e) {
                    get_ed_content = tinymce.activeEditor.getContent();
                    if(get_ed_content != '' && get_ed_content != undefined && get_ed_content != null) {
                        $scope.tinyHasContent = true;
                    } else {
                        $scope.tinyHasContent = false;
                    }
                });
                ed.on('init', function()
                {
                    this.getDoc().body.style.fontSize = '1.2em';
                });

            }
        };

感谢

1 个答案:

答案 0 :(得分:5)

设置新内容后,添加对undoManager.clear()的调用。像这样:

tinymce.activeEditor.setContent('');
tinymce.activeEditor.undoManager.clear()

这将清除活动编辑器的撤消历史记录,因此您无法返回之前的内容。