打字稿Twitter Bootstrap不可注射?

时间:2015-08-24 20:59:33

标签: twitter-bootstrap-3 typescript typescript1.5

我试过

tsd install jquery --save
tsd install bootstrap --save

和tsd.json将是

 {
   "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"
     }
   }
 }

和tsd.d.ts是

/// <reference path="jquery/jquery.d.ts" />
/// <reference path="bootstrap/bootstrap.d.ts" />

所以,我以为我能做到

/// <reference path="../../typings/tsd.d.ts" />

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

但是我有这个警告。

Uncaught TypeError: t(...).modal is not a function

有什么想法吗?

3 个答案:

答案 0 :(得分:0)

提供的代码示例:

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

工作正常as shown in the test file

答案 1 :(得分:0)

TypeScript仅针对开发时间。如果您遇到运行时问题,可能是因为您没有包含某些脚本。

答案 2 :(得分:0)

您提供的说明:

  

tsd install jquery --save

     

tsd install bootstrap --save

为我工作。我在我的主要组件(app.component.ts)中有以下内容:

declare var $:JQueryStatic

我有一个模态组件,我使用以下内容而没有任何抱怨:

@ViewChild('modal') modal: ElementRef

ngAfterViewInit() { $(this.modal).modal() }

我希望它也适合你!