如何让jQuery在我的Typescript文件中工作
How do I get jQuery to work in my Typescript files?
我不明白为什么我的jQuery不能在Typescript文件中工作
我没有任何错误。只是没有反应。当我用class="test"点击div时,什么都不会发生,app.component.ts中的console.log也不会打印到控制台。我被难住了。
以下是我的文件夹结构。感谢您的帮助。感谢
--app
----app.component.ts
----main.ts
--node_modules
--typings
--index.html
--jquery.d.ts
--package.json
--tsconfig.json
--typings.json
以下是我的主要.ts
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
以下是我的应用程序组件。ts
/// <reference path="../jquery.d.ts" />
import {Component} from 'angular2/core';
declare var $: Function;
@Component({
selector: 'my-app',
template: `<h1>My First Angular 2 App</h1>
<div class="test">TEST</div>`
})
export class AppComponent {}
$('.test').click(function(){
$('.test').hide();
console.log('testing');
});
以下是我的index.html文件
<html>
<head>
<title>Angular 2 QuickStart</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- 1. Load libraries -->
<!-- IE required polyfills, in this exact order -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/systemjs/dist/system-polyfills.js"> </script>
<script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
下面是我的tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
以下是我的打字员.json
{
"ambientDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654",
"jasmine": "registry:dt/jasmine#2.2.0+20160412134438"
}
}
使用JQuery.Of('.test')
而不是$('.test')
相关文章:
- 从HTML调用typescript文件中的函数
- 如何让jQuery在我的Typescript文件中工作
- 如何从typescript文件导入javascript文件
- Web Storm 9.0.3 typescript文件观察程序不工作
- 可以't在Visual Studio 2013中编译.d.ts TypeScript文件
- 编译项目中的所有 TypeScript 文件并维护文件结构
- 下载了一个typescript文件,但它抛出了很多错误——我该如何解决
- 编译后按一定顺序连接typescript文件
- 如何在typescript文件中使用流星包
- 在新的typescript文件(0.9)中使用现有的AMD js模块
- 有没有办法在typescript文件中解析c# ?
- 将大型typescript文件拆分为跨多个文件的模块
- Gulp-nodemon监视typescript文件
- 失踪的动能.js Typescript文件中的渐变方法
- 我如何导航到原始的TypeScript文件从JavaScript堆栈在WebStorm与Node
- 为Magnific Popup定义Typescript文件
- TypeScript文件中的JavaScript引用
- 我应该上传ts (typescript)文件或生成的js文件或两者
- Angular-cli没有使用——dev选项生成typescript文件
- 如何在typescript文件位于'./src'时构建输出文件夹