Project, after switching the tab page of the page will be found to upload pictures of the operation error, after checking to find the source of the problem is to switch the tab page Reload page CKEditor will be created again, this time the CKEditor is not the first time to create the one, so the method of uploading pictures will be error.
Workaround: Before ckeditor each time to create a judgment, if there is ckeditor then destroy off, re-create a new, to ensure that there is always only one ckeditor on the page, as follows:
- in ckeditor directive:
console.log (CKEDITOR.instances.myCKeditor);//① if (CKEDITOR.instances.myCKeditor) {// CKEDITOR.instances.myCKeditor.destroy ();} Console.log (CKEDITOR.instances.myCKeditor); ② var ckeditor=ckeditor.replace (// keep creating a new CKEditor console.log (CKEDITOR.instances.myCKeditor); ③
- Description: Where Myckeditor is the name value of textarea in the page
<ckeditor-directive name= "Myckeditor"></textarea >
- The following are the three Console.log printing cases:
- The first time you enter the page because there is no ckeditor exist, so ① and ② are undefined, after the creation of code ③ is created CKEditor object;
- After you switch the tab page, ① is the CKEditor object that was previously created, after the Destroy () method is executed, ② is undefined, and ③ is the new CKEditor object after the code is executed.
Destroy problems of CKEditor in Angularjs