angular2错误:this。$ modal.modal不是函数

Rid*_*dhi 5 bootstrap-modal ng2-bootstrap angular

我收到错误消息:this。$ modal.modal不是函数

我通过gulp文件从wwwroot文件夹中的Node_Module获取了ng2-bs3-modal。

我的文件夹结构是:

 - wwwroot
  - angularlibs
     - angular
     - bootstrap
     - core-js
     - rxjs
     - zone.js
  - ng2-bs3-modal
  - appScripts (js generated from typescripts)
 - Scripts (typescripts)
 - typings
 - gulpfile
 - package.json
 - project.json
 - .....
Run Code Online (Sandbox Code Playgroud)

如果我将ng2-bs3-modal移至Script(typescript)文件夹,则会出现jasmin zone.js错误。使用上述结构,我会收到“ this。$ modal.modal不是函数”错误,因为ng2-bs3-modal的所有打字稿都找不到@ angular / core。

索引html中的脚本标签的顺序如下:

 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"    rel="stylesheet">

 <link rel="stylesheet" ref="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css">

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
Run Code Online (Sandbox Code Playgroud)

我试图通过一些选项来解决,例如:https : //github.com/dougludlow/ng2-bs3-modal/issues/52 https://github.com/dougludlow/ng2-bs3-modal/issues/34

但是没有运气。我是angular2的新手。快速帮助将不胜感激。

Ank*_*wal 6

Install jquery and bootstrap in your project

npm install jquery
npm install bootstrap
Run Code Online (Sandbox Code Playgroud)

then import both in the file (for eg model-view.component.ts) where you are using this modal

import 'jquery';
import 'bootstrap';
Run Code Online (Sandbox Code Playgroud)

For me this worked flawlessly :)


Ism*_*l H 0

你应该包括这个:

<script src="node_modules/ng2-bs3-modal/bundles/ng2-bs3-modal.js"></script>
Run Code Online (Sandbox Code Playgroud)

在您的其他依赖项之后。我强烈建议您考虑使用动态模块加载器,例如systemJS或(我最喜欢的)webpack