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 could also load your jQuery Javascript file in a normal script tag in the head section of your index.html.
...
...
Then in the component or directive where you need it, just declare the $ variable needed for jQuery, since you won't have the typings for all the plugins you need:
import {Directive} from '@angular/core';
declare var $: any;
@Directive({
selector: "my-first-directive"
})
export class MyFirstDirective {
constructor() {
$(document).ready(function () {
alert("Hello World");
});
}
}