javascript - AngularJS using $sce.trustAsHtml with ng-repeat -
i'm trying use $sce.trustashtml() property of object in ng-repeat. result html totally blank. html outputs correctly using ngsanitize though.
<div ng-repeat="question in questions"> <p ng-bind-html="$sce.trustashtml(question.body)"> </p> </div>
i'm on angularjs v1.3.0-beta.3 way. not sure if there's bug or wrong.
you can't use $sce.trustashtml
in expression (unless $sce
property on $scope
) because expressions evaluated in context of $scope
.
the cleanest approach use ngsanitize
.
second cleanest expose $sce.trustashtml
function in $scope
:
<div ng-repeat="..."> <p ng-bind-html="trustashtml(question.body)"></p> </div> $scope.trustashtml = $sce.trustashtml;
Comments
Post a Comment