1

How to bind html content using scope variable (without using ng-bind-html-unsafe) in angularjs

<div ng-controller="dataController">{{test}}</div>

$scope.test = "<div>Html content</div>"
3
  • what is the problem if you use? Commented Apr 5, 2014 at 19:19
  • according to my project guidelines ng-bind should not be used, is there any other way? jsbin.com/kuwovoxa/1/edit Commented Apr 5, 2014 at 19:23
  • 3
    according to your project guidelines then scope variables shouldnt contain html meant to be displayed. Commented Apr 5, 2014 at 19:34

1 Answer 1

3

This is what you are looking for:

Fiddle

function dataController($scope,$sce){
   $scope.test = "<div>Html content</div>";
   $scope.test = $sce.trustAsHtml($scope.test);
}

View

<div ng-bind-html="test"></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.