.net核心angular 6应用ngx-bootstrap无法正常工作错误:“无法获取/”

时间:2018-08-08 09:55:08

标签: .net-core angular6 ngx-bootstrap

我正在尝试让ngx-bootstrap(首先是TooltipModule)在我的.net core 2.1 angular 6应用程序中工作(我已经从angular 5升级到了6)。 我遵循了ngx-bootstrap:tooltip的指示。

所以我执行以下步骤:-

1. npm install ngx-bootstrap --save 

2. // RECOMMENDED (doesn't work with system.js)
   import { TooltipModule } from 'ngx-bootstrap/tooltip';
   // or
   import { TooltipModule } from 'ngx-bootstrap';

   @NgModule({
     imports: [TooltipModule.forRoot(),...]
   })
   export class AppModule(){}

3. <button type="button" class="btn btn-primary"
       tooltip="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
     Simple demo
   </button>

然后,我启动应用程序,并在浏览器上显示“无法获取/”错误。 如果我从AppModules Imports中删除了TooltipModule,则该应用程序将正常加载。

当我检查开发人员控制台时,它说:“无法加载资源:服务器以404()localhost /:1状态响应”

我正在使用Angular CLI:6.1.1和Node:10.7.0,请帮忙。

这是我的angular.json文件:-

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "SyXRiskManagement": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "progress": true,
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "node_modules/ngx-toastr/toastr.css",
              "node_modules/@fortawesome/fontawesome-free/css/all.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            },
            "testing": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.test.ts"
                }
              ]
            },
            "serve": {
              "extractCss": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "SyXRiskManagement:build:serve"
          },
          "configurations": {
            "production": {
              "browserTarget": "SyXRiskManagement:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "SyXRiskManagement:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
            ],
            "assets": [
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "SyXRiskManagement-e2e": {
      "root": "e2e",
      "sourceRoot": "e2e",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "SyXRiskManagement:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "SyXRiskManagement",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "css"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

2 个答案:

答案 0 :(得分:0)

好的,所以我设法找出了问题所在。我真的很傻。我正在运行npm install ngx-bootstrap-保存在错误的文件夹中。所以我将其CD命名为my-app-folder / ClientApp的正确文件夹,运行命令,package.json显示ngx-bootstrap,而node_modules现在具有ngx-bootstrap文件夹,并且导入模块有效:)

答案 1 :(得分:0)

尝试:

ng add @ng-bootstrap/schematics

更新package.json:

"@ng-bootstrap/schematics": "^2.0.0-alpha.1",
"@ng-bootstrap/ng-bootstrap": "^2.0.0-alpha.0",

更新app.module.ts(在导入中):

NgbModule.forRoot()

更新angular.json(以样式显示):

        {"input": "./node_modules/bootstrap/dist/css/bootstrap.css"}