我是 Angular 新手,我一直在嘗試在網站上顯示一些資料。但我得到的只是錯誤
這是我的代碼片段。
ngOnInit(): void {
window.scrollTo(0, 0)
this.loggeduser = JSON.parse(localStorage.getItem('user'))
console.log(this.loggeduser)
this.customer_id = this.loggeduser[0].CUSTOMER_ID
console.log(this.customer_id)
this.http.post('http://localhost:3000/getAdminOrders', JSON.stringify({ 'id': this.customer_id }), { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }).subscribe((res) => {
console.log("res", res)
this.stored = res
console.log(this.stored)
// for (let x = 0; x < this.stored.length; x ) {
// this.stored[x].PURCHASE_DATE = new Date(this.stored[x].PURCHASE_DATE)
// }
})
這是模板內容。
<div class="table-responsive">
<table class="table table-striped" style="width:100%">
<thead>
<tr class="table-secondary">
<th scope="col">Product</th>
<th scope="col">Price</th>
<th scope="col">Order Placed</th>
<th scope="col">Order Id</th>
<th scope="col">Payment Mode</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let stores of stored">
<td>
<div class="media">
<!-- image -->
<div class="d-flex">
<img src="http://localhost:3000/{{stores.PRODUCT_IMAGE}}" height="150px" alt="">
</div>
<div class="media-body">
<h5>{{stores.PRODUCT_PURCHASED}}</h5>
</div>
</div>
</td>
<td>
<h5>{{stores.PRODUCT_PRICE | currency: "₹"}}</h5>
</td>
<td style="width:20%;">
<h5>{{stores.PURCHASE_DATE| date: 'MMM d, y'}} {{stores.PURCHASE_TIME}}</h5>
</td>
<td>
<h5>{{stores.ORDER_ID}}</h5>
</td>
<td style="width:14%">
<h5>{{stores.PAYMENT_MODE}}</h5>
</td>
</tr>
</tbody>
</table>
</div>
有人可以告訴我這有什么問題嗎?
我可以在控制臺中看到從后端獲取的資料。
![找不到型別為“object”錯誤的不同支持物件“[object Object]”](https://i.stack.imgur.com/wQL8F.jpg)
uj5u.com熱心網友回復:
兩個問題。首先,您的財產名稱不是大寫的。它應該像這樣匹配相同的大小寫敏感性
<h5>{{stores.Product_Purchased}}</h5>
該錯誤是由于影像值引起的。由于影像資料回傳一個陣列,您要么需要回圈它,ngFor要么通過索引訪問它
<img src="http://localhost:3000/{{stores.Product_Image.data[0]}}" height="150px" alt="">
uj5u.com熱心網友回復:
我認為你在這一行的問題
<img src="http://localhost:3000/{{stores.PRODUCT_IMAGE}}" height="150px" alt="">
PRODUCT_IMAGE欄位不能for回圈
此致!
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/529100.html
標籤:有角度的打字稿
