Angular 6:找不到名称 'bootbox'

Angular 6 : Cannot find name 'bootbox'

我正在尝试在我的 angular 应用程序中使用 bootbox。我按照 中的说明进行操作。但是当我构建项目时,我得到

error TS2304: Cannot find name 'bootbox'.

我的package.json文件

"dependencies": {
    "@angular/animations": "6.0.2",
    "@angular/common": "6.0.2",
    "@angular/compiler": "6.0.2",
    "@angular/core": "6.0.2",
    "@angular/forms": "6.0.2",
    "@angular/http": "6.0.2",
    "@angular/platform-browser": "6.0.2",
    "@angular/platform-browser-dynamic": "6.0.2",
    "@angular/router": "6.0.2",
    "ag-grid": "17.1.1",
    "ag-grid-angular": "17.1.0",
    "angular2-tree-component": "3.1.0",
    "bootbox": "^4.4.0",
    "bootstrap": "^3.3.7",
    "core-js": "2.5.4",
    "install": "^0.11.0",
    "jquery": "3.3.1",
    "mydatepicker": "2.6.3",
    "ng2-webstorage": "2.0.0",
    "primeng": "6.0.0-alpha.1",
    "rxjs": "6.0.0",
    "rxjs-compat": "6.1.0",
    "zone.js": "0.8.26"
},
"devDependencies": {
    "@angular-devkit/build-angular": "~0.6.3",
    "@angular/cli": "~6.0.3",
    "@angular/compiler-cli": "6.0.2",
    "@angular/language-service": "6.0.2",
    "@types/bootbox": "^4.4.32",
    "@types/bootstrap": "^4.1.0",
    "@types/core-js": "0.9.46",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/jquery": "^3.3.1",
    "@types/node": "8.9.5",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
}

我的angular.json

"scripts": [
    "node_modules/core-js/client/shim.min.js",
    "src/assets/js/Chart.bundle.min.js",
    "node_modules/jquery/dist/jquery.js",
    "node_modules/bootstrap/dist/js/bootstrap.js",            
    "node_modules/bootbox/bootbox.js",
    "src/assets/js/custom.js"
]

我相信,我已正确按照说明进行操作,但无法找到哪里出错了。

尝试在您的组件中导入 bootbox 文件,例如 -

 import * as bootbox from 'bootbox/bootbox.js'

第 1 步: 安装 jquerybootstrap,然后使用 npm

安装 bootbox

第 2 步: 在您的 angular.jsonangular-cli.json for Angular <= v5)文件中,在 [=18 下添加以下内容=]节

"node_modules/jquery/dist/jquery.js",
"node_modules/bootstrap/dist/js/bootstrap.js",            
"node_modules/bootbox/bootbox.js",  

步骤 3: 安装类型

npm install @types/jquery --save
npm install @types/bootbox --save

第四步:构建项目并检查是否构建成功。如果构建成功,则到此为止。

第5步:如果构建不成功,则在你的src文件夹下创建一个名为typings.d.ts的文件并添加以下内容并构建该项目。这应该可以解决问题。

declare var bootbox: any;