简体   繁体   English

AngularJs:在JSP页面显示字符串变量中的HTML个元素

[英]AngularJs: Display HTML elements from string variable in JSP page

I'm using AngularJs and I need to render into a JSP page the HTML elements that are into a string variable in the Controller as below:我正在使用 AngularJs,我需要将 HTML 元素呈现到 JSP 页面中,这些元素是 Controller 中的字符串变量,如下所示:

$scope.myVar = "<h1>Title</h1><p>More information <a href="linkhere">Click here</a></p>";
    

So in JSP page I have something like:所以在 JSP 页面我有类似的东西:

<div class="panel-body">
    {{myVar}}
</div>

But the UI only prints the plain text of the variable.但是 UI 只打印变量的纯文本。 How can I solve this situation?我该如何解决这种情况?

Use AngularJs ng-bind-html directive to render HTML. ( Docs )使用 AngularJs ng-bind-html指令呈现 HTML。(文档

<div class="panel-body" ng-bind-html="myvar"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM