Javascript 允许在角度控制器或视图中使用html标记
我的承包商:Javascript 允许在角度控制器或视图中使用html标记,javascript,angularjs,Javascript,Angularjs,我的承包商: LandingApp.controller('LandingCtrl2', function($scope){ $scope.articles = [ { 'imageSrc' : IMG_DIR + 'spec9.jpg', 'title' : 'Stencils', 'description': 'Plastic or thin metal stencils.<b
LandingApp.controller('LandingCtrl2', function($scope){
$scope.articles = [
{
'imageSrc' : IMG_DIR + 'spec9.jpg',
'title' : 'Stencils',
'description': 'Plastic or thin metal stencils.<br/>100% Custom made'
}
];
});
LandingApp.controller('LandingCtrl2',函数($scope){
$scope.articles=[
{
'imageSrc':IMG_DIR+'spec9.jpg',
“标题”:“模板”,
“描述”:“塑料或薄金属模板。
100%定制”
}
];
});
当我尝试在我的ng中重复(…文章中的文章…{{article.description}}
我得到了
。。。模具。
100%…
,但我需要换行符或其他一些html标记。如何解决这个问题?您需要创建一个方法,该方法可以告诉AngularJS
将该字符串呈现为HTML
例如:
$scope.renderHtml = function (htmlCode) {
return $sce.trustAsHtml(htmlCode);
}
在您的视图中
:
<div ng-bind-html="renderHtml(article.description)"></div>
LandingApp.controller('LandingCtrl2', function($scope,$sce){ ...