2017-06-13 66 views
0

我有的从文本编辑器保存的HTML类型的数据,如何在html中显示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> 

虽然显示我们的角度JS使用

ng-bind-html 

,但我使用的是静态的HTML页面(AMP) 。因此,我怎样才能显示这个内容在一个普通的HTML。可以任何人请帮助我。 放大器我只有使用插值的范围({{}}。任何人都可以请建议我help.Thanks。

回答

0

纳克绑定 - 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>

+0

嗨马赫我使用节点js。 – TSR