[英]How to render text into HTML in AngularJS
I have a variable in a scope with some HTML content. 我在范围内有一个带有一些HTML内容的变量。 I want to render it as HTML on the webpage, but in my case it displays as full text.
我想在网页上将其呈现为HTML,但在我的情况下,它显示为全文。 Can anyone help me?
谁能帮我?
This is my code:- 这是我的代码: -
//contoller.js //contoller.js
$scope.message = '<b><i>result has been saved successfully.</i></b>';
//demo.html //demo.html
<p ng-bind="message"></p>
You need to inject $sce
service into your controller
or Directive
etc. and use $sce service
like this:- 您需要将
$sce
服务注入您的controller
或Directive
等,并使用这样的$sce service
: -
$scope.Message = $sce.trustAsHtml("<b><i>result has been saved successfully.</i></b>");
And bind this in your HTML page eg; 并在HTML页面中绑定它,例如;
<p ng-bind-html = "Message"></p>
<p ng-bind-html="message"></p>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.