簡體   English   中英

動態加載圖像時,Angular2 [src]導致404錯誤

[英]Angular2 [src] causing 404 error when loading image dynamically

在頁面加載為可點擊打開的模式形式后,我將嘗試加載圖像。

我的圖片標簽如下所示:

<img src="/src/files/bstand{{detailEntry.bearbeitungsstand}}.png">

圖像來源正確。 但是,當我加載頁面時,我的變量detailentry為空,因為單擊按鈕即可填充它。 因此控制台向我顯示了404錯誤,網址為:“ / src / files / bstand.png”,該錯誤不存在。請單擊按鈕,正確加載圖像。

我記得我在角度1中使用了ng_src ,我以為[src]是等效的,但它不起作用。

謝謝您的回答!

您可以使用ngIf等待detailEntry

<img *ngIf="detailEntry.bearbeitungsstand" src="/src/files/bstand{{detailEntry.bearbeitungsstand}}.png">

您可以使用* ngIf來防止在沒有有效src的情況下渲染圖像標簽。

<img *ngIf="detailEntry.bearbeitungsstand" src="/src/files/bstand{{detailEntry.bearbeitungsstand}}.png">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM