網上找了很多版本嘗試都不行,最后在stackoverflow上找到一個,嘗試完美解決
具體操作步驟如下
1. 安裝jquery
npm install jquery
2.安裝 type for jquery
npm install -D @types/jquery
3.在組件中使用jquery
impor * from $ from ‘jquery’
import { Component,OnInit,ElementRef } from '@angular/core';
import * as $ from 'jquery';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
greeting(): void {
$("body").append("<h3>test</h3>");
}
}
前台頁面
<div style="text-align:center">
<h1 id="title">
Welcome to {{title}}!
</h1>
<button (click)="greeting()">Clic Me</button>
</div>
