首页 > 解决方案 > 有问题将 bootstrap4-toggle 导入 Angular 8

问题描述

我是 Angular 的新手,我正在尝试从以下来源导入 bootstrap4-toggle: https ://gitbrent.github.io/bootstrap4-toggle/#api 到我的项目中,以添加一个切换复选框:) 我运行 npm安装并且我在packjage.json中找到了项目中的包,现在我需要将它添加到“样式”但我不知道要添加什么,我试过了

 "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "node_modules/bootstrap4-toggle/css/bootstrap4-toggle.min.css",
              "src/styles.css",
              "node_modules/font-awesome/css/font-awesome.css"
            ],

但它没有用......我在导航栏中使用了这个标签

<input type="checkbox" checked data-toggle="toggle">

它应该看起来像一个切换按钮,而不是看起来像一个普通的 html 复选框。

标签: angularbootstrap-4

解决方案


在 angular.json 中的脚本和样式中添加导入

"styles": [
    "src/styles.css",
    "node_modules/bootstrap4-toggle/css/bootstrap4-toggle.min.css"
],
"scripts": [
    "node_modules/bootstrap4-toggle/js/bootstrap4-toggle.min.js"
]

推荐阅读