angular return not found for the product photoes

huangapple go评论65阅读模式
英文:

angular return not found for the product photoes

问题

我有这个问题已经几周了,产品照片返回未找到,而其他属性返回正常,

我已经用Postman测试了API,工作正常,有些地方我可能漏掉了,

我正在使用Angular 15和.NET 7,

产品和照片在控制台日志开发工具中都存在,见附件图片,

Postman:

"pageIndex": 1,
"pageSize": 6,
"count": 21,
"data": [
    {
        "id": 8,
        "name": "ASUS",
        "photoUrl": "images/products/ASUS2.jpg",
        "specification": "ASUS zenbook pro 14 Core i7",
        "generation": "12th Generation",
        "price": 500.99,
        "condition": "New",
        "quantity": 1,
        "storageSize": "512 SSD",
        "ramSize": "32 GB RAM",
        "touchScreen": true,
        "photos": [
            {
                "id": 8,
                "url": "images/products/ASUS2.jpg",
                "isMain": true
            }
        ],
        "productType": "ZenBook",
        "productBrand": "ASUS"
    },

问题:

点击查看问题图片

英文:

i have this problem for several weeks now, the product photos return not found and other property return fine,

i have test the api with postman and work fine , there is something wrong iam missing,
'iam using abgular 15 and .NET7,
the products and the photos are there on console log dev tools, see the attachment picture,

postman:

"pageIndex": 1,
    "pageSize": 6,
    "count": 21,
    "data": [
        {
            "id": 8,
            "name": "ASUS",
            "photoUrl": "images/products/ASUS2.jpg",
            "specification": "ASUS zenbook pro 14 Core i7",
            "generation": "12th Generation",
            "price": 500.99,
            "condition": "New",
            "quantity": 1,
            "storageSize": "512 SSD",
            "ramSize": "32 GB RAM",
            "touchScreen": true,
            "photos": [
                {
                    "id": 8,
                    "url": "images/products/ASUS2.jpg",
                    "isMain": true
                }
            ],
            "productType": "ZenBook",
            "productBrand": "ASUS"
        },

the problem:
enter image description here

答案1

得分: 0

问题不是很清楚,但从我理解的内容来看,您正在发送图像URL,并将图像保存在前端服务器的images文件夹下。您的images文件夹与src文件夹位于同一级别。

您可能忘记将images文件夹的目录添加到angular.json文件中。在angular.json文件的每个项目下,有两个地方可以添加您的目录。

打开您的angular.json文件,

第一个地方 - 项目 -> -> 架构师 -> 构建 -> 选项 -> 资源

第二个地方 - 项目 -> -> 架构师 -> 测试 -> 选项 -> 资源

主要是一个字符串数组,但您也可以通过发送一个对象“{glob,input,output,ignore,followSymlinks}”来更具体地指定要包括和排除的内容。但您只需要将目录作为字符串发送,以便您的资源看起来像这样。

"assets": [
  "images",
…
]

如果您的images文件夹在src下,那么它应该像这样

"assets": [
  "src/images",
…
]

有关更多详细信息,请参阅https://angular.io/guide/workspace-config#asset-config。

英文:

The question is not so clear, but from what I understand is that you are sending the image URLs and you are keeping the images in the frontend server under the images folder. And your images folder is the same level as your src folder.

You probably forget to add the images folder directory into the angular.json file. There are 2 places to add your directory for each project under the angular.json file.

Open your angular.json,

1st place - projects -> <your-project-name> -> architect -> build -> options -> assets

2nd place - projects -> <your-project-name> -> architect -> test -> options -> assets

It is mainly an array of strings but you can be more specific by sending an object of “{glob, input, output, ignore, followSymlinks}” for what to include and what don’t. But what you only need is to send the directory as a string so your assets properly should look like this.

"assets": [
  “images",
…
]

If your images folder is under src then it should look like this instead

"assets": [
  “src/images",
…
]

More details on it https://angular.io/guide/workspace-config#asset-config

huangapple
  • 本文由 发表于 2023年5月28日 02:36:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348448.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定