【发布时间】:2019-10-15 17:15:06
【问题描述】:
我是 Angular 新手,在让 Bootstrap 切换和 Modal 工作时遇到了一些问题。 BootStrap CSS 文件正在工作,因为表单正在接受样式;但是,我认为 JS 文件没有正确链接。请让我知道我在做什么。
我使用 Angular CLI 对 BootStrap 和 jQuery 进行了 NPM 安装。 安装后,我将 BootStrap 和 jQuery 文件链接到 angular.json 文件,以便应用程序能够使用这些库。
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/LyndaChapter1",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
**"styles": [
**"node_modules/bootstrap/dist/css/bootstrap.css",
"src/styles.css"**
],
"scripts": [
"node_modules/bootstrap/dist/js/bootstrap.js",
"node_modules/jquery/dist/jquery.js"
],**
"es5BrowserSupport": true
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
预期结果:切换和模态应该可以工作 实际结果:两者都不起作用
【问题讨论】:
-
你试过把jquery dep放在第一位吗? bootstrap依赖jquery,所以需要先加载。
-
与其依赖 jQuery (应该避免),已经有一个可以使用的引导角度组件包。
-
@Jacquesジャック,谢谢你,我认为你的建议成功了。
-
我将其添加为答案。
标签: angular bootstrap-4 bootstrap-modal angular7 angular-bootstrap-toggle