微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AngularJS如果仅当变量不存在时如何初始化?

如何解决AngularJS如果仅当变量不存在时如何初始化?

我维护旧版软件。 CKEditor的版本:"angular-ckeditor": "~1.0.3",,AngularJS 1.5.0.rc2的版本

文件bower.json

{
  "name": "Packet","version": "1.0.0","authors": [
    "ClipTheme"
  ],"description": "AngularJs Bootstrap Admin Template","keywords": [
    "AngularJS","admin","dashboard","panel","app","charts","components","ui","responsive","layout","route","web","widgets"
  ],"license": "Envato REGULAR LICENSE","homepage": "http://themeforest.net/user/cliptheme/portfolio","private": true,"ignore": [
    "**/.*","node_modules","bower_components","test","tests"
  ],"dependencies": {
    "jquery": "~2.1.3","fastclick": "~1.0.6","angular": "~1.5.0","angular-animate": "~1.5.0","angular-cookies": "~1.5.0","angular-resource": "~1.5.0","angular-sanitize": "~1.5.0","angular-touch": "~1.5.0","angular-ui-router": "~0.2.15","ngstorage": "~0.3.10","angular-translate": "~2.7.2","angular-translate-loader-url": "~2.7.2","angular-translate-loader-static-files": "~2.7.2","angular-translate-storage-cookie": "~2.7.2","angular-translate-storage-local": "~2.7.2","oclazyload": "~0.6.3","angular-breadcrumb": "~0.4.1","angular-bootstrap": "~1.2.1","angular-loading-bar": "~0.7.1","angular-scroll": "~0.6.5","angular-moment": "~1.0.0","angular-swipe": "~0.1.0","AngularJS-Toaster": "~0.4.10","angular-bootstrap-nav-tree": "*","angular-ladda": "~0.3.1","ng-table": "~0.8.3","angular-ui-utils": "mask-0.2.2","ngImgCrop": "~0.3.2","angular-file-upload": "~1.1.5","angular-aside": "~1.3.0","angular-truncate": "*","angular-sweetalert-promised": "~1.0.4","angular-elastic": "~2.4.2","ngmap": "~1.16.7","angular-chart.js": "~0.8.8","angular-ui-switch": "~0.1.1","angular-ckeditor": "~1.0.3","angular-bootstrap-calendar": "~0.18.2","angular-xeditable": "~0.1.9","checklist-model": "~0.2.4","ng-nestable": "~0.0.1","ng-flow": "~2.7.1","v-accordion": "~1.2.7","v-button": "~1.1.1","angular-notification-icons": "~0.4.2","angular-fullscreen": "~1.0.0","angular-awesome-slider": "~2.4.4","angular-appear": "~0.1.1","angular-slick-carousel": "~3.1.4","angular-count-to-0.1.1": "~0.0.3","ng-bs-daterangepicker": "~0.0.5","angular-spectrum-colorpicker": "~1.4.1","ng-notify": "~0.7.1","ng-knob": "~0.1.1","components-modernizr": "~2.8.3","moment": "~2.8.4","perfect-scrollbar": "~0.6.1","ladda": "~0.9.8","sweetalert": "~0.4.2","chartjs": "~1.0.2","ckeditor": "~4.5.6","jquery-nestable": "*","spin.js": "~2.0.2","bootstrap-touchspin": "~3.0.1","d3": "~3.5.9","slick-carousel": "~1.5.9","jquery-appear": "~0.2.4","animate.css": "~3.2.0","font-awesome": "~4.5.0","themify-icons": "~0.1.0","bootstrap": "~3.3.2","flag-icon-css": "~0.8.5","bootstrap-rtl": "~3.3.1","angular-block-ui": "^0.2.2"
  }
}

我有文件MessageViewController.js

app.controller("MessageViewController",["$scope","$rootScope","$stateParams","SweetAlert","toaster","EmailService","EmailSignatureService",function ($scope,$rootScope,$stateParams,SweetAlert,toaster,EmailService,EmailSignatureService) {

        $scope.listAgentReadyTransfer = [];
        $scope.addressCC = null;
        $scope.disableSendReplyMessage = false;
        // <editor-fold defaultstate="collapsed" desc="SHOW,HIDE EDITOR VIẾT
        // EMAIL">
        $scope.showEditor = false;
 
        $scope.clickShowEditor = function () {
            $scope.showEditor = true;

            CKEDITOR.scriptLoader.load([CKEDITOR.basePath+'jquery.min.js',CKEDITOR.basePath+'bootstrap.min.js']);
              let editor = CKEDITOR.replace("editor_message_view",{
                allowedContent :true,fullPage:true,fillEmptyBlocks : true,contentsCss:[CKEDITOR.basePath+'bootstrap.min.css'],toolbar: [
                    { name: 'document',items: [ 'Print' ] },{ name: 'clipboard',items: [ 'Undo','Redo' ] },{ name: 'styles',items: [ 'Format','Font','FontSize' ] },{ name: 'basicstyles',items: [ 'Bold','Italic','Underline','Strike','RemoveFormat','copyFormatting' ] },{ name: 'colors',items: [ 'TextColor','BGColor' ] },{ name: 'align',items: [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock' ] },{ name: 'links',items: [ 'Link','Unlink' ] },{ name: 'paragraph',items: [ 'NumberedList','BulletedList','-','Outdent','Indent','Blockquote' ] },{ name: 'insert',items: [ 'Image','Table' ] },{ name: 'tools',items: [ 'Maximize' ] },{ name: 'editing',items: [ 'Scayt' ] }
                ],customConfig: '',disallowedContent: 'img{width,height,float}',extraAllowedContent: 'img[width,align]',extraPlugins: 'colordialog,colorbutton',// An array of stylesheets to style the WYSIWYG area.
                // Note: it is recommended to keep your own styles in a separate file in order to make future updates painless.
                contentsCss: [ 'https://cdn.ckeditor.com/4.8.0/full-all/contents.css','mystyles.css' ],// This is optional,but will let us define multiple different styles for multiple editors using the same CSS file.
                bodyClass: 'document-editor',// Reduce the list of block elements listed in the Format dropdown to the most commonly used.
                format_tags: 'p;h1;h2;h3;pre',// Simplify the Image and Link dialog windows. The "Advanced" tab is not needed in most cases.
                removeDialogTabs: 'image:advanced;link:advanced',});
            editor.on('instanceReady',function() {
                let element = editor.editable().findOne( '#signatureId' );
                console.log(element);
                if(element){
                    element.remove();
                }
                   EmailSignatureService.getSignatureByQueueName($scope.message.emailQueue).then(function(data){
                       if(data){
                           editor.insertHtml('<div id ="signatureId"><p></p><p></p><p></p><p></p><p style="border-left:1px solid black;padding-left:20px"> '+data.content+'</p>');
                           if(data.image){
                               let fileName =data.image.split(";");
                               for(x in fileName ){
                                   if(x){
                                       editor.insertHtml('<p style="border-left:1px solid black;padding-left:20px"> <img src="./'+fileName[x]+'"</p>'); 
                                   }
                                   
                               }
                           }
                           editor.insertHtml("</div>");
                           window.focus();
                       }
                                    })                     
            })
                 
        };
        $scope.clickHideEditor = function () {
            $scope.showEditor = false;
        };
        // </editor-fold>

当我第一次按下撰写邮件(呼叫clickShowEditor())按钮时,没关系。

enter image description here

当我第二次按下撰写邮件按钮(呼叫clickShowEditor())时,这是错误的,它不再显示CKEditor \

enter image description here

我尝试修复此错误。我认为仅在第一次初始化时检查初始化editor对象是解决错误方法。但是我不知道如何检查初始化CKEditor(如果它不存在)。让我知道。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?