我试图将textAngular实施到使用Angular.js打包的browserify项目中。

我通过rangy安装了textAngularnpm。它们包括如下:

global.rangy = require('rangy');
require('angular-sanitize');
require('textangular');


通过browserifygulp编译软件包时,不会显示错误。但是,一旦单击编辑器工具栏中的按钮,就会出现以下错误:

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函数,但无济于事:

global.rangy.saveSelection = require('rangy/lib/rangy-selectionsaverestore');


这是与该错误报告相同的错误,但对我而言,它仍未修复:https://github.com/fraywing/textAngular/issues/853

感谢您的帮助,如果需要更多信息,请告诉我。

最佳答案

我只能包括来自Github的alex88s答案:

(() => {
  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

但是,我们在Babel中使用了ES6导入,这是从1.5.0开始的工作版本(angulartextAngular版本都设置为此)。

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应该是可选的)。

09-18 19:41