简体   繁体   English

将 Bootstrap 插件添加到 Angular 8

[英]Adding Bootstrap Plugins to Angular 8

I'm new to Angular and trying to figure out how to bring in a Bootstrap Plugin, specifically the Bootstrap Toggle , to Angular 8. Here is what I have tried.我是 Angular 的新手,并试图弄清楚如何将 Bootstrap 插件,特别是Bootstrap Toggle引入 Angular 8。这是我尝试过的。

Installed bootstrap , jquery , popper.js , bootstrap-toggle安装bootstrap , jquery , popper.js , bootstrap-toggle

In angular.json I addedangular.json我添加了

    "styles": [
      "src/styles.css",
      "./node_modules/bootstrap-toggle/css/bootstrap-toggle.min.css",
      "./node_modules/bootstrap/dist/css/bootstrap.min.css"
    ],
    "scripts": [
      "./node_modules/jquery/dist/jquery.min.js",
      "./node_modules/popper.js/dist/umd/popper.min.js",
      "./node_modules/bootstrap-toggle/js/bootstrap-toggle.min.js",
      "./node_modules/bootstrap/dist/js/bootstrap.min.js"
    ]

In the app.module.ts I addedapp.module.ts我添加

import bootstrap from "bootstrap";

Then for testing I added the following to the app.component.html然后为了测试,我将以下内容添加到app.component.html

<div class="container">
    <p> Please enter your name</p>
    <form class="form-inline">
        <div class="form-group col-sm-12 justify-content-center">
            <div class="col-sm-6">
                <input class="form-control" style="width:100%" #invitation>
            </div>
            <button type="submit" class="btn btn-primary">Search</button>

        </div>            
    </form>
    <input type="checkbox" checked data-toggle="toggle">
</div>

The checkbox is not changed to a toggle.复选框不会更改为切换。 Any ideas why?任何想法为什么?

https://stackblitz.com/edit/angular-tlghnn https://stackblitz.com/edit/angular-tlghnn

Try to add like this 尝试这样添加

<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="switch1">
<label class="custom-control-label" for="switch1">Toggle me</label>
</div>

i think the problem is declaring styles in 我认为问题在于声明样式

angular.json -> ./node_modules/bootstrap-toggle/css/bootstrap-toggle.min.css angular.json-> ./node_modules/bootstrap-toggle/css/bootstrap-toggle.min.css

it can't find this node module make sure that you have installed it correctly, if it is the correct then it is the problem with providers of that package. 它找不到此节点模块,请确保您已正确安装它,如果正确,则说明该软件包的提供程序存在问题。 you can use one of the answers above they work fine 您可以使用上面的答案之一,它们可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM