代码之家  ›  专栏  ›  技术社区  ›  Anand Murali

角度6:找不到名称“bootbox”

  •  1
  • Anand Murali  · 技术社区  · 7 年前

    我正在尝试在角度应用程序中使用bootbox。我听从了这个指示 answer . 但是当我建造这个项目的时候

    错误TS2304:找不到名称“bootbox”。

    my 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"
    }
    

    我的角.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"
    ]
    

    我相信,我已经正确地遵循了这些指示,但是我找不到哪里出了问题。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Anand Murali    6 年前

    步骤1: 安装 jquery , bootstrap 然后 bootbox 使用NPM

    第2步: 在你的 angular.json ( angular-cli.json 对于angular<=v5)文件,请在下面添加以下内容 scripts 部分

    "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
    

    第4步: 生成项目并检查生成是否成功。如果生成成功,请在此处停止。

    第5步: typings.d.ts 在你的 src 文件夹并添加以下内容并生成项目。这样可以解决问题。

    declare var bootbox: any;
    
        2
  •  0
  •   RemyaJ    7 年前

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

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