[英]Allow html tags in Angular controller or view
my contrller : 我的控制者:
LandingApp.controller('LandingCtrl2', function($scope){
$scope.articles = [
{
'imageSrc' : IMG_DIR + 'spec9.jpg',
'title' : 'Stencils',
'description': 'Plastic or thin metal stencils.<br/>100% Custom made'
}
];
});
when i try in My ng repeat (...article in articles...) {{article.description}} i got ... stencils.<br/>100% ....
, but i need break line or some other html tags. 当我尝试ng重复(...文章中的文章...){{article.description}}时,我得到了
... stencils.<br/>100% ....
,但是我需要换行或一些其他html标签。 How can i solve this? 我该如何解决?
You need to make a method, which can tell AngularJS
to render that string as a HTML
您需要制作一个方法,该方法可以告诉
AngularJS
将字符串呈现为HTML
Example : 范例:
$scope.renderHtml = function (htmlCode) {
return $sce.trustAsHtml(htmlCode);
}
And in your view
: 在您
view
:
<div ng-bind-html="renderHtml(article.description)"></div>
Don't forget to include $sce
in your controller 不要忘记在控制器中包含
$sce
LandingApp.controller('LandingCtrl2', function($scope,$sce){ ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.