Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 允许在角度控制器或视图中使用html标记_Javascript_Angularjs - Fatal编程技术网

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){ ...