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

慕尼黑的夜晚無(wú)繁華
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
您需要遵循的簡(jiǎn)單解決方案是
transformYourHtml(htmlTextWithStyle) {
return this.sanitizer.bypassSecurityTrustHtml(html);
}
- 3 回答
- 0 關(guān)注
- 912 瀏覽
添加回答
舉報(bào)
0/150
提交
取消