.net-core - .net core angular 6 app ngx-bootstrap 不工作错误:'Cannot GET /'
问题描述
我正在尝试让 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"
}
}
}
解决方案
尝试:
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"}
推荐阅读
- c# - 保存带有图纸的面板 C#
- javascript - Webpack 4 配置未选择 index.js 文件
- reactjs - React & es6 : 返回中的条件渲染
- python - Python中的“stderr”有什么意义?
- windows - 如何使用 VB.NET 检测屏幕 DPI?
- c# - 在 EntityFramework 和 .net 核心依赖注入中使用一个 dbContext 和多个连接字符串
- monitoring - OpenNMS 在收集时跳过某些 JMX MXBean
- javascript - 如何测试结果的类型是否是 Jest 中的 javascript“函数”?
- git - 如何在 Gerrit UI 中创建一个新的 .git-project 作为另一个目录下的子目录?
- c# - 是否使用“连接池”