javascript - 在 Internet Explorer 中初始化 Rangy.js 时出错

标签 javascript angularjs internet-explorer rangy textangular

我正在开发一个使用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 上运行良好。该演示和我的应用程序之间的一个不同之处是我使用的是未缩小的范围库。最后,这些错误不会发生在 Chrome 或 Firefox 上。

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

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

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

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

谢谢!

最佳答案

看起来 textAngular 初始化范围选择太早了。我通过在 2036 年更新 textAngular/dist/textAngular.js 来修复此问题,以在检查范围库之前等待加载

    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.");
            }
        }
    };

关于javascript - 在 Internet Explorer 中初始化 Rangy.js 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31899422/

相关文章:

html - IE、Chrome 和 FireFox 的保存密码行为说明

javascript - 在命令提示符下安装 npm

javascript - 在 firebase 中克隆直接数组

javascript - 如何为响应式菜单的下拉设置动画?

javascript - 每次点击时都会再次调用自定义函数

javascript - 手动引导 Angular 应用程序以创建异步应用程序初始化

javascript - Angular : $rootScope variable vs event

html - css 下拉菜单在 IE 中不起作用

javascript - 如何将大流转换为 gzipped base64 字符串

html - 过渡和伪元素的组合在 IE 中不起作用?