【问题标题】:Angular cli assets photo issue - giving 404 not foundAngular cli资产照片问题-找不到404
【发布时间】:2017-12-10 08:41:21
【问题描述】:

我正在尝试像这样从 assets 文件夹中导入图像文件 背景: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": {} } }

【问题讨论】:

  • 使用./assets/ ....
  • 试过不行
  • 我在 dist 中也找不到这些图片
  • 匹配你的cli和我的答案。将 [assets] 替换为 assets

标签: angular angular-cli


【解决方案1】:

在您的 Angular cli 中,您需要设置您的资产目录。 angular-cli.json

 "apps": [
        {
          "root": "src",
          "outDir": "dist",
          "assets": [
            "assets", // set here your whatever dir  where you store images
            "favicon.ico"

确保您在 Angular cli 中的目录。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-22
    • 2018-03-02
    • 2017-01-20
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    相关资源
    最近更新 更多