在Angular 5中导入自定义CSS和JS时出错

时间:2019-02-27 11:42:44

标签: css angular angular5

我真的很想如何将自定义的CSS和JS导入到Angular5项目中。

我是Angular的新手,所以对我做错了的事情的解释会很棒。

我想在项目中全局导入css样式。

项目的结构为:

 -representacioApp
 --representacio-app
 ---src
 ----assets
 -----css
 ------style.css
 -----vendors
 ------css
 -------vendor.bundle.base.css
 -------vendor.bundle.addons.css
 ------iconfonts
       ...
 ---.angular-cli.json

和代码

我的.angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "representacio-app"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "prt",
      "styles": [
        "assets/css/style.css",
        "assets/vendors/iconfonts/mdi/css/materialdesignicons.min.css",
        "assets/vendors/iconfonts/font-awesome/css/font-awesome.min.css",
        "assets/vendors/css/vendor.bundle.base.css",
        "assets/vendors/css/vendor.bundle.addons.css"
      ],
      "scripts": [
        "assets/vendors/js/vendor.bundle.base.js",
        "assets/vendors/js/vendor.bundle.addons.js",
        "assets/js/off-canvas.js",
        "assets/js/hoverable-collapse.js",
        "assets/js/misc.js",
        "assets/js/settings.js",
        "assets/js/todolist.js",
        "assets/js/dashboard.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "devCa": "environments/environment.dev.ca.ts",
        "devEs": "environments/environment.dev.es.ts",
        "devCaMock": "environments/environment.dev.ca.mock.ts",
        "devEsMock": "environments/environment.dev.es.mock.ts",
        "prodCa": "environments/environment.prod.ca.ts",
        "prodEs": "environments/environment.prod.es.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "src/tsconfig.spec.json",
      "exclude": "**/node_modules/**"
    },
    {
      "project": "e2e/tsconfig.e2e.json",
      "exclude": "**/node_modules/**"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

文件的路径已正确写入,因此问题不在这里,我尝试读取该错误,但是正如我所说的,我在角度上还很陌生,不习惯这种错误。

css或哪里有很多错误?

错误代码:https://justpaste.it/6iq4p

2 个答案:

答案 0 :(得分:0)

尝试这样

src/assets/css/style.css

答案 1 :(得分:0)

对于所有文件,请尝试

 ./src/assets/css/style.css

希望它会起作用