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 install dt~jquery --save --global
So now i have jquery
folder under typings/global
folder in my project directory. In addition the following new line has been added to my typings.json
file:
{
"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"
}
}
I started to write a new Angular2 directive (that I imported into app-module
file) but I do not know how to correctly import jQuery library. Here is my source file:
import {Directive} from '@angular/core';
@Directive({
selector: "my-first-directive"
})
export class MyFirstDirective {
constructor() {
$(document).ready(function () {
alert("Hello World");
});
}
}
But I can't use nor $
nor jQuery
. What is the next step?
.dropdown()
method for example... – Sheply.dropdown()
is not a function of jquery. Are u using bootstrap.js ? If u are using it then you have to use jquery or just switch to ng-bootstrap which is bootstrap wriiten for angular by angular team search google. – Pitiless