Angular2 如何使用jquery


網上找了很多版本嘗試都不行,最后在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>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM