简体   繁体   English

如何在html中显示html类型保存的内容?

[英]How to display html type saved content in html?

I have a data of type html which is been saved from a text editor, 我有一个html类型的数据,该数据是从文本编辑器保存的,

<p style=\"font-size: 14px;text-align: justify;\">
 <a href=\"https://www.xpertdox.com/disease-description/Chronic%20Kidney%20Disease\" style=\"background-color: transparent;\">Chronic kidney disease</a>, 
<p>also known as chronic kidney failure, is a condition characterized by gradual loss of kidney function and affects around 26 million adults in the United States.
The kidneys are supposed to filter excess fluid and waste from the blood which is then excreted in the urine via the bladder.</p>

While displaying we use 在显示时,我们使用

ng-bind-html

in angular js but I am using a static html pages(AMP).Therefore how can I display this content in a plain html.Can any one please help me. 在angular js中,但是我使用的是静态html pages(AMP)。因此,我如何以纯html显示此内容。任何人都可以帮助我。 In amp I have only have scope to use interpolation({{}}).Can anyone please suggest me help.Thanks. 在耳放中,我只能使用插值({{}})。有人可以建议我帮忙。谢谢。

ng-bind-html need to get codes as Html , for that we use $sce.trustAsHtml() , see the sample ng-bind-html需要将代码获取为Html ,为此我们使用$sce.trustAsHtml()请参见示例

 var app = angular.module("app", []); app.controller("ctrl", [ "$scope", "$sce", function($scope, $sce) { var html = "<p style=\\"font-size: 14px;text-align: justify;\\">" + "<a href=\\"https://www.xpertdox.com/disease-description/Chronic%20Kidney%20Disease\\" style=\\"background-color: transparent;\\">Chronic kidney disease</a>, " + "<p>also known as chronic kidney failure, is a condition characterized by gradual loss of kidney function and affects around 26 million adults in the United States." + "The kidneys are supposed to filter excess fluid and waste from the blood which is then excreted in the urine via the bladder.</p>"; $scope.content = $sce.trustAsHtml(html); $scope.content2 = html; } ]); app.filter("trustAsHtml", function($sce) { return function(html) { return $sce.trustAsHtml(html); } }) 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div class="container" ng-app="app" ng-controller="ctrl"> <h1>convert to Html from controller</h1> <div ng-bind-html="content"></div> <h1>convert to Html with filter</h1> <div ng-bind-html="content2 | trustAsHtml"></div> </div> 

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

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