在Angular2中使用jquery方法:
首先在index.html中引入jquery文件
<script src="https://cdn.bootcss.com/jquery/2.1.3/jquery.js"></script>
接下来定义使用它:
import {Component , ElementRef,OnInit} from '@angular/core';
declare var jQuery:any; //定义jquery
@Component({
template :`
<button>点击</button>
})
export class TestComponent implements OnInit {
constructor(public _elementRef: ElementRef){}
ngOnInit():any{
jQuery(this._elementRef.nativeElement).on('click',function(){
console.log(123);
})
}
}
jQuery修改为$符号也可以的
https://stackoverflow.com/questions/30623825/how-to-use-jquery-with-angular