Javascript 检查tinyMCE是否有内容

Javascript 检查tinyMCE是否有内容,javascript,jquery,angularjs,tinymce,Javascript,Jquery,Angularjs,Tinymce,我试图查看我的tinyMCE在编写时是否有内容,如果有,我会设置一个标志(我使用的是AngularJS)。这是我用于微型计算机的代码: $scope.tinyHasContent = false; tinymce.init({ selector: "#elm1", height: 400, language:'it', plugins: [

我试图查看我的tinyMCE在编写时是否有内容,如果有,我会设置一个标志(我使用的是AngularJS)。这是我用于微型计算机的代码:

$scope.tinyHasContent = false;
tinymce.init({
                selector: "#elm1",
                height: 400,
                language:'it',
                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('NodeChange', function(e){

                        if(ed.getContent() != '' || ed.getContent() != undefined || ed.getContent() != null) {
                            $scope.tinyHasContent = true;
                            console.log('the content ' + ed.getContent() + " " + $scope.tinyHasContent);
                        } else {
                            $scope.tinyHasContent = false;
                            console.log('the content ' + ed.getContent() + " " + $scope.tinyHasContent);
                        }
                    });
                }
            });
简单地说,当我打字时,我可以看到我正在写的日志。但问题是,即使在init上,似乎也始终存在一个内容,因为它在日志中始终返回$scope.tinyHasContent=true。怎么可能

顺便说一下,总结一下,这是我应该做的:

<div ng-if="tinyHasContent == false">
 <p>Hello</p>
</div>

你好


但实际上它不起作用

问题是
ed。getContent()
返回默认的根块元素(即段落),即使您没有键入任何内容。这就是为什么
tinyHasContent
总是正确的原因

要验证这一点,您可能需要将
ed.getContent()
打印到控制台