1
根據https://angular.io/docs/ts/latest/guide/webpack.html你應該能夠在vendor.ts添加廠商如jQuery文件如何使用vendor.ts從https://angular.io/docs/ts/latest/guide/webpack.html
// Other vendors for example jQuery, Lodash or Bootstrap
// You can import js, ts, css, sass, ...
我做了什麼至今
typings install dt~jquery --global --save
npm install jquery --save
,我加入這行vendor.ts
import 'jquery'
用的WebPack運行出錯。但我無法在我的組件中使用jQuery。
import { Component, OnInit, ElementRef } from '@angular/core';
@Component({
selector: 'table-widget',
templateUrl: 'table-widget.component.html'
})
export class TableWidgetComponent implements OnInit {
constructor(private _elRef: ElementRef) {
}
ngOnInit() : void {
$(this._elRef.nativeElement).find('button').on('click', function() { alert("it works"); });
}
}
我在做什麼錯在這裏?
感謝:-)它的工作原理 – kuerbi