Angular2 如何使用jquery

網上找了不少版本嘗試都不行,最後在stackoverflow上找到一個,嘗試完美解決css

具體操做步驟以下html

1. 安裝jqueryjquery

     npm install jquerynpm

2.安裝 type for jqueryapp

    npm install -D @types/jquerycomponent

3.在組件中使用jqueryhtm

  impor * from $ from ‘jquery’blog

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>");
  }
}

  

前臺頁面it

<div style="text-align:center">
  <h1 id="title">
    Welcome to {{title}}!
  </h1>  
  <button (click)="greeting()">Clic Me</button>
</div>
相關文章
相關標籤/搜索