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