我试图从资产文件夹中导入图像文件,就像这样 background:url(' ../../ assets / img / drag-icon.png')
它会出现此错误并且不会加载图像
http://localhost:4200/assets/img/drag-icon.png
我也无法在dist中找到这些图像
这是我的angularcli.json
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "project": { "name": "app-name" }, "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": "wf", "styles": [ "styles.scss" ], "scripts": [], "environmentSource": "environments/environment.ts", "environments": { "dev": "environments/environment.ts", "prod": "environments/environment.prod.ts" } } ], "e2e": { "protractor": { "config": "./protractor.conf.js" } }, "lint": [ { "project": "src/tsconfig.app.json" }, { "project": "src/tsconfig.spec.json" }, { "project": "e2e/tsconfig.e2e.json" } ], "test": { "karma": { "config": "./karma.conf.js" } }, "defaults": { "styleExt": "scss", "component": {} } }
答案 0 :(得分:1)
在你的角度cli中你需要设置资产目录。的角cli.json 强>
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets", // set here your whatever dir where you store images
"favicon.ico"
确保你的目标在角度cli。