I tried
tsd install jquery --save
tsd install bootstrap --save
and tsd.json would be
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"jquery/jquery.d.ts": {
"commit": "c5a2f44bab06cf9f2bcc14530171daac1cebff6c"
},
"bootstrap/bootstrap.d.ts": {
"commit": "c5a2f44bab06cf9f2bcc14530171daac1cebff6c"
}
}
}
and tsd.d.ts was
/// <reference path="jquery/jquery.d.ts" />
/// <reference path="bootstrap/bootstrap.d.ts" />
so, I thought I could do
/// <reference path="../../typings/tsd.d.ts" />
import $ = require('jquery');
$('#modal').modal();
But I’ve got this Warning.
Uncaught TypeError: t(...).modal is not a function
Any ideas ?
3
Answers
The provided code sample:
Works fine as shown in the test file
TypeScript is aimed for development time only. If you are having runtime issues it’s probably because you didn’t include some scripts.
The instructions that you provide:
Worked for me. I have in my main component (
app.component.ts
) the following:declare var $:JQueryStatic
And I have a component for modals where I use the following without any complains:
@ViewChild('modal') modal: ElementRef
ngAfterViewInit() {
$(this.modal).modal()
}
I hope it works for you too!