我想建立一个证明网站与AngularJS 1.1.5和PHP如何呈现从JSON换行到HTML
我有包括姓名,消息和日期的JSON对象的数组。
真实的证言将是属性消息,并且会有证书中的换行符。
[
{
"Name": "Snow White",
"Message": "Dear all, I need a new line <br> Is it possible to do it in AngularJS?",
"Date": "16/11/2013"
},
{
"Name": "Cinderalla",
"Message": "Dear all, I need a new line <br> Is it possible to do it in AngularJS?",
"Date": "10/11/2013"
},
{
"Name": "Ariel",
"Message": "Dear all, I need a new line <br> Is it possible to do it in AngularJS?",
"Date": "20/06/2013"
}
]
使用$资源获取数组并将其链接到$ scope.Ctestimonials后,我用NG-重复渲染所有对象到HTML。
<div id="testimonialbody" ng-controller="TestimonialCtrl">
<ul class="testimonialul">
<li ng-repeat="testimonial in Ctestimonials" class="testimonialclass">
<blockquote> {{testimonial.Message}}
</blockquote>
<cite>{{testimonial.Name}}, {{testimonial.Date}}</cite>
</li>
</ul>
</div>
但是,我无法在HTML页面中正确显示换行符。有谁知道我该怎么做?
谢谢
看看ng-bind-html – epascarello
@epascarello想到这一点,但不是暴露在跨脚本攻击? – Wilson