2015-09-14 26 views
0

我要顯示在HTML的一些數據,該數據是這樣的文字: <p>abcd efg hijk....(<a href=\"http:\/\/www.facebook.com\/stock\/NBR\">NYSE:NBR<\/a>),,你看,有 一些html標籤,但是當我使用angularJS爲了顯示這些數據,瀏覽器無法將這些數據識別爲html標籤。如何使用AngularJS來顯示HTML標籤中

任何人都知道如何做到這一點?

+2

你如何運用。請分享更多代碼。 – Vineet

+0

https://docs.angularjs.org/api/ng/directive/ngBindHtml – Michelangelo

回答

0

您可以使用ngBindHtml

<ANY 
    ng-bind-html="expression"> 
... 
</ANY> 

假設您對$ scope.htmtText = ....有價值。然後

<div ng-bind-html="htmtText"></div> 

documentation

0

您可以使用ng-bind-html="myHTML",在angularjs

$scope.myHTML = 
    'I am an <code>HTML</code>string with ' + 
    '<a href="#">links!</a> and other <em>stuff</em>'; 

顯示HTML,需要ngsanitize注入模塊angular.module('bindHtmlExample', ['ngSanitize']), 還需要包括依賴<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-sanitize.js"></script>

+1

值得一提的是,如果你使用ng-bind-html,'$ sanitize'也需要在模塊級注入。 –