我正在尝试导入 twitter-bootstrap-wizard我将 javascript 库添加到我的 angular 2
项目中,但总是收到此错误:
WEBPACK_IMPORTED_MODULE_1_jquery(...).bootstrapWizard is not a function
我只是使用 angular-cli 1.0.0
创建一个新的 angualr 应用程序,然后在 index.html 中添加脚本,如下所示:
<body>
<app-root>Loading...</app-root>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap-wizard/1.2/jquery.bootstrap.wizard.js"></script>
</body>
然后在我的组件中:
//
declare var bootstrapWizard : any;
import * as $ from 'jquery';
//
ngAfterViewInit() {
(<any>$('#wizard')).bootstrapWizard()
}
最佳答案
如果你使用cdn,只需添加声明
declare const jQuery: any;
或者您可以删除 cdn,然后从 npm 安装 jquery,然后使用您的导入
npm i --save jquery
import * as $ from 'jquery';
关于javascript - 无法将外部js与Angular2一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43452155/