【发布时间】:2021-08-04 15:23:31
【问题描述】:
我的 API 返回属于产品的图像路径,但我的 Angular 应用程序没有显示图像。
HTML 代码
<ng-container *ngFor="let prod of productData">
<div class="row p-2 bg-white border rounded" style="margin-bottom: 10px;">
<div class="col-md-3 mt-1">
<img class="img-fluid img-responsive rounded product-image"
src="{{prod.ProductImages.ImagePath}}"
[alt]="prod.ProductImages.Name">
</div>
<div class="col-md-6 mt-1">
<h5>{{prod.Name}}</h5>
<div class="mt-1 mb-1 spec-1">
|<span> {{prod.Shape.Name}}</span>
|<span class="dot"></span><span> {{prod.StoneType.Name}}</span>
|<span class="dot"></span><span> {{prod.Color.Color1}}<br></span>
</div>
<div class="mt-1 mb-1 spec-1"><span>{{prod.Supplier.Name}}</span></div>
</div>
<div class="align-items-center align-content-center col-md-3 border-left mt-1">
<div class="d-flex flex-row align-items-center">
<h4 class="mr-1">{{prod.SellingPrice | currency:'RS: '}}</h4>
</div>
<div class="d-flex flex-column mt-4">
<button class="btn btn-primary btn-sm" type="button" (click)="editProduct(prod.Id)">Details</button>
<button class="btn btn-outline-primary btn-sm mt-2" type="button">Add to wishlist</button>
</div>
</div>
</div>
</ng-container>
跨域读取阻止 (CORB) 阻止了 MIME 类型为 text/html 的跨域响应 https://localhost:44349/。详情请见https://www.chromestatus.com/feature/5629709824032768。
如果我像下面这样添加,上面的消息会显示
<img class="img-fluid img-responsive rounded product-image"
src="https://localhost:44349/{{prod.ProductImages.ImagePath}}"
[alt]="prod.ProductImages.Name">
【问题讨论】:
-
如果你在浏览器中打开了路径,你能看到图像工作吗?请把完整的网址也放在这里
-
@WasimNabil 然后它显示一个警告消息我也附上了那个消息
-
如果您在浏览器 URL 中打开 localhost:44349/Images/Product/6ycFZe.jpg,图像是否有效?没有在应用中加载它
-
@WasimNabil 是的,它正在显示我的图像
标签: angular asp.net-web-api angular10