npm install jquery --save
npm install --save jquery @types/jquery
プロジェクトフォルダのnode_modulesフォルダに@typesフォルダが作成され、jQueryの型定義ファイルがインストールされます。
types に jquery を追加
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types" : [
"jquery"
]
},
src\app\app.component.ts
toggleTitle(){
const jqobj :JQuery = $(".title");
jqobj.slideToggle().fadeOut();
}
src\app\app.component.html
<h1 class="title" style="display:none">
{{title}}
</h1>
<button (click)="toggleTitle()"> clickhere</button>
ng serve --open