2017-01-10 46 views
0

我試圖在組件模板中添加jquery onclick事件,例如, app.component.html在angualr2組件模板中添加jquery

<li> 
    <a id="menu-close" href="#services">Services</a> 
</li> 

和我在一個custom.js寫了一個函數文件如

$("#menu-close").click(function(e) { 
    .... 
} 

但我不知道如何加載custom.js,只是添加

<script src="js/custom.js"></script> 

index.html中?

+0

當你使用'angular'你不需要'jquery'。嘗試在'html'中實現像ng-click這樣的角度選項。也加載'custom.js'爲你的'js'文件 –

回答

0

你只是試試這個...

// In the console 
// First install jQuery 
npm install --save jquery 
// and jQuery Definition 
npm install -D @types/jquery 

導入您的jQuery ..

// CommonJS style - working with "require" 
import $ = require('jquery') 
// 
//then add your jquery here... 
$("#menu-close").click(function(e) { 
    .... 
} 
+0

@ user7393721指定相對路徑正確地需要你的jquery .. –