【问题标题】:.net core angular 6 app ngx-bootstrap not working error: 'Cannot GET /'.net core angular 6 app ngx-bootstrap 不工作错误:'Cannot GET /'
【发布时间】:2018-08-08 09:55:08
【问题描述】:

我正在尝试让 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>

然后我启动应用程序,我在浏览器上收到错误消息“Cannot GET /” 如果我从 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"
    }
  }
}

【问题讨论】:

  • 我刚刚看到在我的 packages.json 文件中没有 ngx-bootstrap 并且在我的 node_modules 文件夹中没有 ngx-bootstrap 文件夹。这可能是错吗

标签: .net-core angular6 ngx-bootstrap


【解决方案1】:

好的,所以我设法找出问题所在。我真的觉得自己很傻。我在错误的文件夹中运行 npm install ngx-bootstrap --save 。所以我 cd 到正确的文件夹,即 name-of-my-app-folder/ClientApp 运行命令,package.json 在那里显示 ngx-bootstrap 并且 node_modules 现在有 ngx-bootstrap 文件夹并且导入模块工作:)

【讨论】:

    【解决方案2】:

    试试:

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

    【讨论】:

      猜你喜欢
      • 2019-08-04
      • 2019-02-19
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 2019-02-06
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多