I want to wrap some jQuery code in an Angular2 directive.
I installed jQuery library for Typings into my project with the following command:
typings in
You should have a typings.json that points to your jquery typing file. Then:
systemjs.config (notice map setting for jquery)
System.config({
defaultJSExtensions: true,
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
map: {
'app': 'app',
jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js',
material: 'npm:material-design-lite/dist/material.min.js',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
....
},
packages: {
app: { main: 'main', format: 'register', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' }
},
});
In component:
import $ from 'jquery';
Then use $ as usual.