我正在使用Angular 4.我面临着从文本字符串呈现HTML(带CSS)的问题。是否可以通过Html Agility包?如果是,我该如何使用它?你能提供一个在Angular -2或Angular-4中使用的样本吗?
我也使用了innerHtml属性,但它没有显示Css样式。
我的代码片段:
x.component.ts:
private _messageText: string="<html><body><p><b>This text is bold</b></p><p><i>This text is italic</i></p></body></html>";
x.html:
<div class="textarea-preview" [innerHTML]="_messageText"></div>
x.css
.textarea-preview
{
width: 100%;
border: none;
pointer-events: none;
background-color: transparent;
resize: none;
outline: none;
font-size: 1rem;
-webkit-appearance: none;
overflow-x: hidden;
overflow-y: hidden;
}
输出是:
This text is bold
This text is italic
期望的输出:
"This text is bold" must be in bold as we are using <b></b> tag here.
"This text is italic" must be in italic as we are using <i></i> tag here.
but it is displaying in simple text format not displaying style tags and css.