Twitter bootstrap 无法在Angular2中使用引导JS

Twitter bootstrap 无法在Angular2中使用引导JS,twitter-bootstrap,angular,typescript,Twitter Bootstrap,Angular,Typescript,我正在使用angular cli创建一个项目,该项目使用了一些引导js函数,如button()和modal(),但问题是,尽管我能够完美地编译ts文件,但当我实际尝试在浏览器中执行javascript函数时,它却失败了 error_handler.js:53 TypeError: button.button is not a function at NewdeviceComponent.loading (newdevice.component.ts:122) at Newdevi

我正在使用angular cli创建一个项目,该项目使用了一些引导js函数,如button()和modal(),但问题是,尽管我能够完美地编译ts文件,但当我实际尝试在浏览器中执行javascript函数时,它却失败了

error_handler.js:53 TypeError: button.button is not a function
    at NewdeviceComponent.loading (newdevice.component.ts:122)
    at NewdeviceComponent.add (newdevice.component.ts:97)
    at CompiledTemplate.proxyViewClass.View_NewdeviceComponent0.handleEvent_67 (component.ngfactory.js:517)
    at CompiledTemplate.proxyViewClass.<anonymous> (view.js:408)
    at HTMLButtonElement.<anonymous> (dom_renderer.js:276)
    at ZoneDelegate.invokeTask (zone.js:265)
    at Object.onInvokeTask (ng_zone.js:227)
    at ZoneDelegate.invokeTask (zone.js:264)
    at Zone.runTask (zone.js:154)
    at HTMLButtonElement.ZoneTask.invoke (zone.js:335)
奇怪的是VSCode给了我智能感知,编译实际上成功了,但在浏览器中失败了

所有引导文件和样式表都从angular-cli.json全局加载

"scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ]

使用Bootstrap的JS意味着您必须加载jQuery、Bootstrap的JS,并可能围绕Bootstrap的JS代码创建角度包装。但是,即使这样做也会导致相当糟糕的集成,因为jQuery和Angular都会为DOM更新而“斗争”——这两个库的原理非常不同


在Angular环境中,最好使用专用的本机库,为Angular用户提供更好的API。Angular和Bootstrap 4有一个很好的实现:。通过使用它,您可以跳过整个jQuery/Bootstrap JS故事。

您是如何在项目中包含Bootstrap JS的?@AngularFrance在angular-cli.json中。脚本部分。检查编辑。听起来不错。也许你需要使用像?AngularFrance这样的包装库不,我不这么认为。如果文件已加载,我应该能够使用它们。我不能在这里使用它们的原因是什么?Bootstrap 3有包装吗?@pkozlowski.opensource:and之间的主要区别是什么?我提到的是Bootstrap 4。这是有道理的,因为Bootstrap3不再维护,Bootstrap4即将测试版。是的,但我的整个项目都是bootstrap3@AngularFrance我认为API(易用性、灵活性)和ng引导的质量要高得多。这主要是由于一些ng bootstrap成员也是Angular团队的一部分。另一个原因是高度关注自动化测试。如果有兴趣,我可以向你提供更多细节。
"scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ]