2

我正在开发一个使用 textAngular 的 Angular 应用程序,它依赖于 rangy-core 和 rangy-selectionsaverestore。我在使用最新的 IE 时遇到以下错误:

Module 'WrappedSelection' failed to load: Unspecified error.
Error: Unspecified error.
    at Anonymous function (js/plugins/textAngular/rangy-core.js:2970:29)
    at Anonymous function (js/plugins/textAngular/rangy-core.js:2923:14)
    at Anonymous function (js/plugins/textAngular/rangy-core.js:415:21)
    at Module.prototype.init (js/plugins/textAngular/rangy-core.js:387:13)
    at init (js/plugins/textAngular/rangy-core.js:294:17)
    at loadHandler (js/plugins/textAngular/rangy-core.js:3825:17)

Module 'SaveRestore' failed to load: Unable to get property 'isDirectionBackward' of undefined or null reference
TypeError: Unable to get property 'isDirectionBackward' of undefined or null reference
    at Anonymous function (js/plugins/textAngular/rangy-selectionsaverestore.js:30:9)
    at Anonymous function (js/plugins/textAngular/rangy-core.js:415:21)
    at Module.prototype.init (js/plugins/textAngular/rangy-core.js:387:13)
    at init (js/plugins/textAngular/rangy-core.js:294:17)
    at loadHandler (js/plugins/textAngular/rangy-core.js:3825:17)

此错误似乎发生在远程初始化期间。

奇怪的是,TextAngular 演示在 Internet Explorer 上运行良好。演示和我的应用程序之间的一个不同之处在于我使用的是未缩小的 rangy 库。最后,这些错误不会在 Chrome 或 Firefox 上发生。

虽然应用程序加载(我认为上面的错误只是控制台中的警告),但当我单击 textAngular 字段时,我看到以下错误:

对象不支持属性或方法“getSelection”文件:textAngular.js,行:693,列:4

我在 textAngular 或 rangy github 中找不到解决这些问题的任何内容。以前有人遇到过这些问题吗?

如果有帮助,我可以将链接发布到我们的应用程序。

谢谢!

4

4 回答 4

3

看起来 textAngular 过早地初始化范围选择。我通过更新 textAngular/dist/textAngular.js ln 2036 以在检查 rangy 库之前等待 onload 解决了这个问题

    window.onload = function() {
        // Ensure that rangy and rangy.saveSelection exists on the window (global scope).
        // TODO: Refactor so that the global scope is no longer used.
        if(!window.rangy){
            throw("rangy-core.js and rangy-selectionsaverestore.js are required for textAngular to work correctly, rangy-core is not yet loaded.");
        }else{
            window.rangy.init();
            if(!window.rangy.saveSelection){
                throw("rangy-selectionsaverestore.js is required for textAngular to work correctly.");
            }
        }
    };
于 2015-10-15T17:36:54.507 回答
1

我遇到了同样的问题。我尝试了建议的 window.onload 修复,但它让我遇到了另一个关于 textAngularSetup 未加载的错误。我修复了 window.onload 并包含了 textAngularSetup.js 文件。它现在在 Chrome 和 IE 中运行良好。我很困惑,因为我没有看到演示中包含该文件。

于 2015-10-21T17:20:26.187 回答
0

sharing my solution, I also got the same issue in IE 11(edge mode), tried with above solution(window.onload), but issue was still persisted in the app.

I have done following changes,

  1. Added window.onload as in above solution, textangular.js - run() function

  2. Replaced textangular-rangy.min.js with rangy.core and rangy-selectionsaverestore dependencies,

Modified the core code to handle the exception,

File: rangy-core.js, line number:2967-2972

                        var r2;
                        try {
                            // code generating above exception 
                            r2 = r1.cloneRange()
                            r1.setStart(textNode, 0);
                            r2.setEnd(textNode, 3);
                            r2.setStart(textNode, 2);
                            sel.addRange(r1);
                            sel.addRange(r2);
                            selectionSupportsMultipleRanges = (sel.rangeCount == 2);
                        } catch (e) {
                            selectionSupportsMultipleRanges = false;
                        }

It might help, tested in IE11 and chrome

于 2017-04-06T17:06:22.310 回答
0

我在将第三方工具加载到我依赖 textangular-rangy.min.js 的模式弹出窗口时遇到了同样的问题

我已将 textangular-rangy.min.js 替换为 rangy.core 和 rangy-selectionsaverestore 依赖项,修改了核心代码以处理异常,

文件:rangy-core.js,行号:2967-2972

 var r2;
                        try {
                            // code generating above exception 
                            r2 = r1.cloneRange()
                            r1.setStart(textNode, 0);
                            r2.setEnd(textNode, 3);
                            r2.setStart(textNode, 2);
                            sel.addRange(r1);
                            sel.addRange(r2);
                            selectionSupportsMultipleRanges = (sel.rangeCount == 2);
                        } catch (e) {
                            selectionSupportsMultipleRanges = false;
                        }

它适用于 IE11 和 chrome :)

于 2018-04-11T11:43:02.493 回答