skip to Main Content

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


  1. The provided code sample:

    import $ = require('jquery');
    $('#modal').modal();
    

    Works fine as shown in the test file

    Login or Signup to reply.
  2. TypeScript is aimed for development time only. If you are having runtime issues it’s probably because you didn’t include some scripts.

    Login or Signup to reply.
  3. The instructions that you provide:

    tsd install jquery --save

    tsd install bootstrap --save

    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!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search