1

我正在尝试textAngularAngular.js使用browserify.

我安装rangytextAngular通过npm. 它们是这样包含的:

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

使用browserifyvia编译包时gulp,不会显示错误。但是,只要单击编辑器工具栏中的按钮,就会出现以下错误:

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 。

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

4

1 回答 1

2

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

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';

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).

于 2016-02-12T09:54:22.077 回答