TypeError:g.rangy.saveSelection不是使用textangular + rangy + browserify的函数 [英] TypeError: g.rangy.saveSelection is not a function using textangular + rangy + browserify
问题描述
我正在尝试在使用browserify
打包的Angular.js
项目中实现textAngular
.
I am trying to implement textAngular
into my Angular.js
project that is packaged using browserify
.
我通过npm
安装了rangy
和textAngular
.它们包括如下:
I installed rangy
and textAngular
via npm
. They are included like this:
global.rangy = require('rangy');
require('angular-sanitize');
require('textangular');
当通过gulp
用browserify
编译软件包时,未显示任何错误.但是,一旦单击编辑器工具栏中的按钮,就会出现以下错误:
When compiling the package with browserify
via gulp
, no errors are shown. However, as soon as I click on a button in the toolbar of the editor, I get the following error:
TypeError: g.rangy.saveSelection is not a function
at Scope.m.startAction (http://localhost:3000/js/main.js:38077:9364)
at Scope.executeAction (http://localhost:3000/js/main.js:38076:5862)
at fn (eval at <anonymous> (http://localhost:3000/js/main.js:18310:15), <anonymous>:4:230)
at callback (http://localhost:3000/js/main.js:28558:17)
at Scope.$eval (http://localhost:3000/js/main.js:20997:28)
at Scope.$apply (http://localhost:3000/js/main.js:21097:25)
at HTMLButtonElement.<anonymous> (http://localhost:3000/js/main.js:28563:23)
at HTMLButtonElement.dispatch (http://localhost:3000/js/main.js:3252:214)
at HTMLButtonElement.elemData.handle (http://localhost:3000/js/main.js:3209:98)
我也试图包括这样的saveSelection
函数,但无济于事:
I also tried to include the saveSelection
function like this to no avail:
global.rangy.saveSelection = require('rangy/lib/rangy-selectionsaverestore');
与该错误报告相同的错误,但对我而言仍未得到解决: https ://github.com/fraywing/textAngular/issues/853 .
It is the same error as this bug report, but for me it is still not fixed: https://github.com/fraywing/textAngular/issues/853.
我们非常感谢您的帮助,如果需要更多信息,请告诉我.
Help is appreciated, if more info is needed, please let me know.
推荐答案
我只能包含来自Github的alex88s答案:
I can only include alex88s answer from Github:
(() => {
window.taTools = {};
window.rangy = require('rangy/lib/rangy-core');
})();
require('rangy/lib/rangy-selectionsaverestore');
require('textangular/dist/textAngular-sanitize');
require('textAngular/dist/textAngularSetup');
require('textAngular/dist/textAngular');
https://github.com/fraywing/textAngular/issues/1056
但是我们将 ES6 导入与 Babel 一起使用,这是我们从1.5.0
开始的工作版本(angular
和textAngular
版本均设置为这个).
However we are using ES6 imports with Babel, and this is our working version as of 1.5.0
(both angular
and textAngular
versions are set to this).
import rangy from 'rangy/lib/rangy-core';
(() => {
window.taTools = {};
window.rangy = rangy;
})();
import 'rangy/lib/rangy-selectionsaverestore';
import 'textangular/dist/textAngular-sanitize';
import 'textAngular/dist/textAngularSetup';
import 'textAngular/dist/textAngular';
import 'textAngular/dist/textAngular.css';
但是,我们真正认为应该将其简化为仅两行(一个用于加载缩小版本,另一对CSS应该是可选的).
However we truly think that this should be really simplified to just 2 lines (one is for loading the minified version and the other should be optional for the CSS).
这篇关于TypeError:g.rangy.saveSelection不是使用textangular + rangy + browserify的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!