Angular cli 资产照片问题 - 找不到 404 [英] Angular cli assets photo issue - giving 404 not found
问题描述
我正在尝试从这样的资产文件夹中导入图像文件背景:url('../../assets/img/drag-icon.png')
I'm trying to import the image file from assets folder like this background: url('../../assets/img/drag-icon.png')
它给出了这个错误并且不加载图像http://localhost:4200/assets/img/drag-icon.png
it gives this error and doesn't load the image
http://localhost:4200/assets/img/drag-icon.png
我在 dist 中也找不到这些图片
I couldn't find those images in dist as well
这是我的 angularcli.json
This is my angularcli.json
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json",项目": {"name": "app-name" }, "apps": [{"root": "src","outDir": "dist",资产":[[资产]",favicon.ico"],"index": "index.html","main": "main.ts","polyfills": "polyfills.ts","test": "test.ts","tsconfig": "tsconfig.app.json","testTsconfig": "tsconfig.spec.json","前缀": "wf",风格":[样式.scss"],脚本":[],"environmentSource": "environments/environment.ts",环境":{"dev": "环境/environment.ts","prod": "环境/environment.prod.ts"}} ], "e2e": {量角器":{配置":./protractor.conf.js"} },皮棉":[{项目":src/tsconfig.app.json"},{项目":src/tsconfig.spec.json"},{项目":e2e/tsconfig.e2e.json"} ], 测试": {业力":{配置":./karma.conf.js"} },默认值":{"styleExt": "scss",组件":{} } }
推荐答案
在您的 angular cli 中,您需要设置您的资产目录.angular-cli.json
in your angular cli you need to set you asset dir. angular-cli.json
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets", // set here your whatever dir where you store images
"favicon.ico"
确保你的目录在 angular cli 中.
这篇关于Angular cli 资产照片问题 - 找不到 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!