我有导入和使用的jQuery范围滑块小部件,如下所示:
declare var jQuery: any;
import 'jquery-ui/ui/widgets/slider';
import 'jquery-ui/ui/widgets/mouse';
并像这样使用它:
jQuery(this.elementRef.nativeElement).find('#range-slider').slider({..});
我的滑块工作正常。
问题是我需要启用移动触摸的滑块,所以我导入了jQuery UI Touch Punch:
declare var jQuery: any;
import 'jquery-ui/ui/widgets/slider';
import 'jquery-ui/ui/widgets/mouse';
import 'jquery-ui-touch-punch';
但出现以下错误:
TypeError: Cannot read property 'prototype' of undefined
显然,它找不到jQuery和jQuery UI。但是,当导入的jQuery不在全局范围内时,如何通过jQuery进行打孔?
我将这个样板用于我的项目。
这为我工作(排序而不是滑块,但想法相同):
import * as $ from 'jquery';
import 'jquery-ui/ui/widgets/sortable';
(window as any).jQuery = $;
require('jquery-ui-touch-punch');
最后需要而不是导入很重要。如果您使用导入,则在触摸打孔导入之后,将不会运行将jQuery全局窗口设置为Windows的代码,因为导入会先于其他所有内容运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句