简体   繁体   中英

Why bootstrap not getting loaded properly at Angular CLI MVC based project

I dont know whay bootstrap is not loaded properly at angular CLI Typescript based ASP.NET MVC based project. Somehow, seems default CSS files are overriden or i dont know exactly about the problem and no idea how to figure it out. I almost tried all solutions available on stackoverflow.com

For example following Bootstrap snippet not showing panel headers.

<div class="panel panel-default">
  <!-- Default panel contents -->
  <div class="panel-heading">Panel heading</div>
  <div class="panel-body">
    <p>...</p>
  </div>
</div>

I just created Angular app via CLI and modified package.json within the app. I did not copied the whole content at root folder.

So my solution structure is :

在此处输入图片说明

Moreover, part of angular.json is :

    "schematics": {
        "@schematics/angular:component": {
          "styleext": "scss"
        }
      },
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "index": "src/index.html",
            "main": "src/main.ts",
            "outputPath": "../wwwroot/dist",
            "polyfills": "src/polyfills.ts",
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"
            ],
            "styles": [
              "node_modules/bootstrap/scss/bootstrap.scss"
              "src/styles.scss"
            ],
            "tsConfig": "src/tsconfig.app.json"
          },
           .............

and packages.json is :

      "version": "0.0.0",
      "scripts": {
      "ng": "ng",
      "start": "ng serve",
      "build": "ng build",
      "test": "ng test",
      "lint": "ng lint",
      "e2e": "ng e2e"
    },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.1.3",
    "@angular/cdk": "^7.1.1",
    "@angular/common": "~7.1.0",
    "@angular/compiler": "~7.1.0",
    "@angular/core": "~7.1.0",
    "@angular/forms": "~7.1.0",
    "@angular/material": "^7.1.1",
    "@angular/platform-browser": "~7.1.0",
    "@angular/platform-browser-dynamic": "~7.1.0",
    "@angular/router": "~7.1.0",
    "core-js": "^2.5.4",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26",
    "bootstrap": "4.1.3",
    "jquery": "^3.3.1"
  },

  "devDependencies": {
    "@angular-devkit/build-angular": "~0.11.0",
    "@angular/cli": "~7.1.3",
    "@angular/compiler-cli": "~7.1.0",
    "@angular/language-service": "~7.1.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/jquery": "^3.3.27",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.6"
  }

Any body can let me know how to resolve this frustrating functioning error?

Since from what I can tell you don't even need the scss in your compile pipeline and you just need the css, change this;

"styles": [
   "node_modules/bootstrap/scss/bootstrap.scss"
   "src/styles.scss"
],

to this;

"styles": [
   "./node_modules/bootstrap/dist/css/bootstrap.min.css"
   "src/styles.scss"
],

...and ya should be good. Cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM