2017-06-13 67 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