我正在开发一个使用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/