我有一個在開發模式下完美運行的 Angular 14 應用程式。在構建到生產期間一切順利。當我進入生產頁面時,控制臺中出現此錯誤:
Cannot read properties of undefined (reading 'absiccValues')
我在以下示例中使用了一個名為“bafBackgroundColor”的自定義管道,錯誤出現在該管道的引數中(第 3 行)
<ng-container *ngFor="let item of col.field; let i = index">
<input type="number" step="any" [(ngModel)]="piece[item.field_name]"
[style.backgroundColor]="piece[item.field_name] | bafBackgroundColor:item.field_name:scp_list[i]['absiccValues']">
{{scp_list[i]['absiccValues'].max}}
{{i}}
</ng-container>
該錯誤告訴我它在我的 scp_list 陣列的索引“i”中找不到“abcissValues”,但是當我在輸入之外顯示相同的值時,使用“{{scp_list[i] ['absiccValues'].max}} "(上面示例的第 4 行),它可以作業
uj5u.com熱心網友回復:
沒有足夠的代碼來具體說明,所以就這樣做
bafBackgroundColor:item.field_name:scp_list[i]?.absiccValues"
這可能是因為您的資料沒有及時加載或一些類似的問題。您在本地模式下的 API 比在 prod 模式下更快,因此您看不到問題,但問題就在那里。
*ngIf如果您愿意,您還可以使用宣告來保護您的標簽以避免這種情況。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/516437.html
標籤:有角度的生产角14
