我從HTTP調用中獲取大量HTML代碼。我將HTML塊放在一個變量中并使用[innerHTML]將其插入到我的頁面中,但我無法設置插入的HTML塊的樣式。有沒有人有任何建議如何實現這一目標?@Component({selector: 'calendar',template: '<div [innerHTML]="calendar"></div>',providers:[HomeService], styles: [` h3 {color:red;}`})我想要設置樣式的HTML是變量“calendar”中包含的塊。
3 回答

慕尼黑的夜晚無繁華
TA貢獻1864條經驗 獲得超6個贊
您需要遵循的簡單解決方案是
transformYourHtml(htmlTextWithStyle) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
- 3 回答
- 0 關注
- 916 瀏覽
添加回答
舉報
0/150
提交
取消