2013-07-24 48 views
11

我的數據庫存儲產品信息,其中很多都是按列表組織的。我將數據加載到Angular中作爲$scope.postAngularJS - 渲染包含在字符串中的HTML標記

例如,

$scope.post.size_description = '<li> Fits true to size. Take your normal size\r</li> 
    <li> Slim-cut, mid-rise style</li> 
    <li> Long in length, alter to fit</li> 
    <li> Model wears an IT 48\r</li> 
    <li> Model measures: waist size 32, height 6\'1"/ 185cm\r</li>'. 

當我嘗試這個數據加載到我的角的應用程序,它就會呈現爲文本(即<li>不被解析)。我知道這可能是出於安全原因,但有沒有辦法解決它?

+1

可能重複的[插入HTML到視圖中使用AngularJS](http://stackoverflow.com/questions/9381926/insert-html-into-view-using-angularjs) –

+0

看看:http://docs.angularjs.org/api/ng.$compile – Cherniv

+0

我在這裏找到了更完整的答案:[link](http://stackoverflow.com/questions/9381926/insert- html-into-view-using-angularjs) – gianlucabr

回答

9

由於Damax在這裏說:https://stackoverflow.com/a/11640420/769083

<div ng-bind-html-unsafe="post.size_description"></div> 
+4

ng-bind-html-unsafe已經從Angular 1.2折舊了。請參閱http://stackoverflow.com/questions/9381926/insert-html-into-view-using-angularjs –