如何显示java字符串附加html标签,在angalrjs前端的html行为



我在java中有一个字符串,我需要动态地将html标签附加到它,以便在显示在它的前面时,可以感受到html标签的行为。如:

String content="Hello World,this is a test <em>content</em> to demonstrate the requirement";

在上述字符串中,内容被包装在<em>标记中。但是当我试图在angularjs前端显示它时,字符串没有采取标签行为并显示为"Hello World,这是一个测试content来演示需求"。

使用angular- sanizize .js示例

<div ng-controller="testCtrl">
   <div ng-bind-html="stringTest"></div>
</div>

您可以使用ng-bind-html

<div ng-controller="testCtrl">
   <div ng-bind-html="stringTest"></div>
</div>

然而,如果你发现这个指令限制太大,当你绝对相信你要绑定的内容的来源,那么你也可以使用ng-bind-html-unsafe

<div ng-controller="testCtrl">
   <div ng-bind-html-unsafe="stringTest"></div>
</div>

最新更新