簡體   English   中英

在角度7中顯示異步數據

[英]Displaying async data in angular 7

我從服務器獲取一個對象,該對象在一個字段中包含html標記。 因此,要使角度顯示它成為此代碼的一部分。

<p class="desc" [innerHTML]="sanitizer.bypassSecurityTrustHtml(o.description)"></p>

與本地數據完美配合。 雖然,根據服務器的數據,我將其用於其他領域 這樣的參數{{o?.category}} 但是在描述字段中,我遇到了這個錯誤,

錯誤TypeError:無法讀取未定義的屬性“描述”

那么,有什么選擇呢? 在byPassSecurityTrustHtml里面?

您沒有在示例中使用elvis運算符,這是:

<p class="desc" [innerHTML]="sanitizer.bypassSecurityTrustHtml(o.description)"></p>

應該:

<p class="desc" [innerHTML]="sanitizer.bypassSecurityTrustHtml(o?.description)"></p>

暫無
暫無

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

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