我正在使用Angular2,我想包括jQuery。SystemJS:加載jQuery
systemjs.config.js
(function (global) {
System.config({
paths: {
'npm:': 'node_modules/',
'jquery': "//code.jquery.com/jquery-2.1.4.min.js"
},
meta: {
bootstrap: {
deps: ['jquery']
}
},
.....
}
在app.module.ts,我得到了錯誤:找不到模塊 'jQuery的'當我把:
import $ from 'jquery';
我嘗試使用map來代替路徑,但是同樣的re SULT ..
默認情況下,TypeScript會在「node_modules」目錄中查找軟件包。你用'npm'安裝了jQuery嗎? – martin
我已經有**/dev/assets/js **文件夾中的jquery不在** node_modules ** –
這就是爲什麼它不起作用,TypeScript可以找到'jquery'並引發錯誤。使用jquery它實際上更復雜,你也需要安裝它的類型。如果您使用的是TypeScript 2.0,您可以使用https://www.npmjs.com/package/@types/jquery – martin