2017-01-10 65 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 .. –