Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUNEDITOR.convertContentsForEditor.consistencyCheck.fail] TypeError: Cannot read property 'removeChild' of undefined #336

Closed
mehmetotkun opened this issue Apr 15, 2020 · 8 comments
Labels
Milestone

Comments

@mehmetotkun
Copy link

I am getting below error when trying to use suneditor with angularjs.

After initialize below error occurred.

image

@JiHong88
Copy link
Owner

Hi, @mehmetotkun
Show me editor's declaration part with options.

@JiHong88 JiHong88 added this to the 2.29.0 milestone Apr 17, 2020
@mehmetotkun
Copy link
Author

Here is complete directive. I declare editor after scripts loading is complated.

.directive('sunEditor', ['$ocLazyLoad', '$timeout', function ($ocLazyLoad, $timeout) {
        return {
            restrict: 'AC',
            //scope: true,
            require: 'ngModel',
            compile: function (tElm, tAttr, transclude) {
                if (!window.sunEditorPromise) {
                    window.sunEditorPromise =
                    $ocLazyLoad.load([{
                        files: [
                            'https://cdn.jsdelivr.net/npm/suneditor@latest/dist/css/suneditor.min.css',
                            'https://cdn.jsdelivr.net/npm/suneditor@latest/dist/suneditor.min.js',
                            'https://cdn.jsdelivr.net/npm/suneditor@latest/src/lang/en.js'
                        ]
                    }]);
                }
                return function postLink(scope, element, attr, controller) {
                    var options = attr.options;
                    var isEditorChange = false;
                    var suneditor;
                    window.sunEditorPromise.then(function () {
                        if (attr.sunEditor == 'sipmle') {
                            suneditor = SUNEDITOR.create((element[0]), {
                                formats: ['p', 'div', 'h2', 'h3', 'h4'],
                                height: 'auto',
                                buttonList: [

                                    ['formatBlock', 'bold', 'underline', 'italic', 'link', 'superscript', 'list'],
                                    ['removeFormat'],
                                    ['fullScreen', 'showBlocks', 'codeView'],
                                    ['preview', 'print'],
                                    ['undo', 'redo'],
                                ],
                                lang: SUNEDITOR_LANG['en']
                            });
                        } else {
                            suneditor = SUNEDITOR.create((element[0]),
                                {
                                    formats: ['p', 'div', 'h1', 'h2', 'h3', 'h4'],
                                    height: 'auto',
                                    buttonList: [
                                        ['formatBlock', 'bold', 'underline', 'italic', 'link', 'superscript', 'list', 'table'],
                                        ['link', 'image', 'video'],
                                        ['removeFormat'],
                                        ['fullScreen', 'showBlocks', 'codeView'],
                                        ['preview', 'print'],
                                        ['undo', 'redo'],
                                    ],
                                    lang: SUNEDITOR_LANG['en']
                                });
                        }

                        suneditor.onChange = function (contents) {
                            isEditorChange = true;
                            $timeout(function () {
                                var cleanContent = contents.replaceAll('<br>', '').replaceAll('<br/>', '').replaceAll('<p></p>', '').replaceAll('<span></span>', '')
                                    .replaceAll('<b></b>', '').replaceAll('<i></i>', '').replaceAll('<strong></strong>', '')
                                var contentEl = angular.element(cleanContent);
                                contentEl.find('br').remove();
                                contentEl.find('*:empty').remove();
                                controller.$setViewValue(contentEl[0]);
                            })
                        }
                    })
                    scope.$watch(attr.ngModel, function (newVal, oldVal) {
                        if (!isEditorChange && suneditor && newVal) {
                            suneditor.setContents(newVal || "");
                            scope.$watch(attr.ngModel, function () { });
                        }
                    })
                }
            }
        
        };
    }])

@JiHong88
Copy link
Owner

@mehmetotkun
Can you show me the editor's initialize data?
<textarea>${data}</textarea>

JiHong88 added a commit that referenced this issue May 6, 2020
delete core-fileInfoPlugins
@JiHong88 JiHong88 closed this as completed May 6, 2020
@mehmetotkun
Copy link
Author

Sorry @JiHong88 for late.

I bind data to the textarea by ng-model
<textarea ng-model="$textModel"></textarea>

@JiHong88
Copy link
Owner

JiHong88 commented May 8, 2020

The 2.29.0 version has been updated.
If this issue has not been resolved, please reopen this issue.
Thank you.

@mehmetotkun
Copy link
Author

mehmetotkun commented Jul 3, 2020

image
Nowi there is another bug

@JiHong88 JiHong88 reopened this Jul 4, 2020
@JiHong88 JiHong88 added the bug label Jul 4, 2020
@JiHong88 JiHong88 modified the milestones: 2.29.0, 2.31.0 Jul 4, 2020
@JiHong88 JiHong88 closed this as completed Jul 4, 2020
@JiHong88
Copy link
Owner

JiHong88 commented Jul 5, 2020

The 2.31.0 version has been updated.
If this issue has not been resolved, please reopen this issue.
Thank you.

@JiHong88
Copy link
Owner

I think the cause of the error seems to be this.#430 (comment)
Please refer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants