2015-11-04 91 views
0

我正在尝试查看我的tinyMCE是否在写入时有一个内容,如果是或不是(我使用的是AngularJS),我设置了一个标志。因此,这是我使用的微型代码:检查tinyMCE是否有内容

$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> 

,但实际上它不工作

回答

0

事情是ed.getContent()回报 - 即使你没有在任何类型的 - 默认的根块元素(即段落)。这就是为什么tinyHasContent永远是真的。

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