1

The Output in the inspect element:

<div ng-bind-html="job.description" class="ng-binding">
    "<p><strong>Our Responsibilities</strong></p>"
</div>

This is my HTML code:

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.20/angular.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.3.20/angular-sanitize.min.js"></script>

var myApp = angular.module('rivigoApp', ['ngSanitize']);

<div ng-bind-html="job.description"></div>

How do I do to make it compile the HTML in the output? I believe the main issue is with the quotes "" but I'm unable to figure out how to proceed. I've tried using various other methods.

3
  • 1
    Please share how job.description is defined in your controller. Commented Jun 22, 2017 at 0:47
  • in general, if you are storing HTML in javascript variables, you are probably not using angular in the best manner. Commented Jun 22, 2017 at 0:55
  • {{job.description}} is just another field. Commented Jun 22, 2017 at 2:21

1 Answer 1

1

inject $sce Service in your controller and use it like below

app.controller('mainCtrl',function($sce , $scope){
     $scope.job = {
        description : $sce.trustAsHtml("<p><strong>Our Responsibilities</strong></p>")
    };

    })

$sce Reference

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. However, that's not the only html tag and so hard coding it doesn't make sense. The {{job.description}} is also 2 pages long of html codes.

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.