我想在Angular 2组件中使用FitVids JQuery插件。我尝试在jquery.d.ts文件中的JQuery接口中添加fitVids函数,但得到错误。我使用的是typescript。谢谢大家!
我使用了在GitHub上找到的这个jquery.d.ts文件。我将其修改为:
[...]
queue(queueName: string, callback: Function): JQuery;
fitVids(selector?: any, opts?: any): JQuery;
}
declare module "jquery" {
export = $;
}
declare var jQuery: JQueryStatic;
declare var fitVids: JQueryStatic;
我得到的错误是:
EXCEPTION: EXCEPTION: Error during instantiation of Articolo!.
ORIGINAL EXCEPTION: TypeError: jQuery(...).fitVids is not a function
发布于 2016-02-06 22:36:34
您遇到的问题来自于编译时和运行时之间的差异
通过将fitvids
添加到.d.ts
文件中,您可以正确地设置编译时方法的定义
然而,在运行时中,您的应用程序正在寻找该定义的实现,但是找不到。
您需要将fitvids的.js
文件添加到index.html
页面
<script src="path/to/fitvids.js"></script>
https://stackoverflow.com/questions/35240773
复制