如何将 jQuery 与 Angular 结合使用? https://stackoverflow.com/questions/30623825/how-to-use-jquery-with-angular
如何将 jQuery 导入 Angular 2 Typescript 项目? https://stackoverflow.com/questions/39511788/how-to-import-jquery-to-angular2-typescrypt-projects
我不知道这是否安全,但肯定会对您有所帮助。相当
1st Step
来自index.html
我的测试项目\src\index.html
在下面输入 jQuery cdnapp-root
tag.
...
<body>
<app-root></app-root>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</body>
...
2nd Step
my-test-project\src\app\test\test.component.ts
转到所需的组件 .ts 脚本。
import { Component, OnInit } from '@angular/core';
// this line will allow you to use jQuery
declare var $: any;
@Component({
...
})
3rd Step
my-test-project\src\app\test\test.component.ts
通过日志记录测试 jQuery'I<3Cats'
jQuery 语法内部$(() => { /* content here */ })
.
export class TestComponent implements OnInit {
constructor() { }
ngOnInit() {
$(() => {
console.log('hello there!');
});
}
}
您还可以将此技术与其他 JavaScript 库一起使用。我不知道这是否安全,但肯定会对您有所帮助。辞职
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)