我有一个导入和使用的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触摸屏
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来触摸穿孔呢?
我在我的项目中使用这样板。
发布于 2017-09-02 20:00:04
这对我起了作用(可排序而不是滑块,但同样的想法):
import * as $ from 'jquery';
import 'jquery-ui/ui/widgets/sortable';
(window as any).jQuery = $;
require('jquery-ui-touch-punch');需求而不是最终的导入是重要的。如果使用导入,设置jQuery全局on窗口的代码将在触摸穿孔导入之后才能运行,因为导入比其他所有操作都要运行。
https://stackoverflow.com/questions/39348579
复制相似问题