我有一个使用Typescript的Angular 2应用程序。我想用jQuery的$
各种任务,如
$(document).ready(function(){ // throwing error: "[ts] Cannot find '$'. any"
console.log("loaded up!");
$("#main_div").niceScroll();
})
我已导入jQuery.min.js通过index.html文件到我的应用程序,像这样:
<script src="app/libs/jquery.min.js"></script>
然而,我关于jQuery代码,没有将任何内容导入app.component.ts
文件。是否有必要,如果是的话,我该如何导入它?
import { GenericService } from './services/Generic.service'; // did not do this
import $ from './libs/jquery.min.js'; // tried this but does not work
令人惊讶的是,我的代码昨天工作,因为我正在开发,但不是今天当我跑npm start
。任何人都可以帮我解决这个导入过程吗?
什么'/// <参考路径=“../ typings/jquery.d.ts”/>'do?它似乎被注释掉了,所以我很困惑。 –
它告诉TypeScript编译器在搜索类型定义时包含该文件。 [更多信息](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) – rinukkusu
@KangzeHuang更多信息在这里:https://github.com/Microsoft/TypeScript-Handbook/blob /master/pages/Namespaces%20and%20Modules.md#-reference-ing-a-module – Dinistro