I am looking to enclose some jQuery code within an Angular2 directive.
To incorporate the jQuery library for Typings into my project, I utilized the following command:
typings install dt~jquery --save --global
As a result, a jquery
folder now resides under the typings/global
directory in my project. Furthermore, the typings.json
file includes a new entry:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160602141332",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160807145350",
"jquery": "registry:dt/jquery#1.10.0+20160908203239"
}
}
While developing a new Angular2 directive (subsequently imported into the app-module
file), I encountered difficulty importing the jQuery library correctly. Below is the excerpt from my source file:
import {Directive} from '@angular/core';
@Directive({
selector: "my-first-directive"
})
export class MyFirstDirective {
constructor() {
$(document).ready(function () {
alert("Hello World");
});
}
}
Unfortunately, both $
and jQuery
are inaccessible to me. What should be my next course of action?