Show user input as HTML – angular1

I have in my controller a variable, which is defined on the $scope, which contains an html input.

function init() {
        $scope.message = params.message;
    }

Where params.message could be for example something like this:

<h1>Hellow world</h1><p>Hi again</p><br><br> <b> End </b>

in the html I use it like this:

    <div ng-show="showTab == 'EN'">
        <div class='library-padding'>
            <p>{{message}}></p>
        </div>
    </div>

I want it to be shown as parsed html, meaning that the tags themselves will not appear, but it’s displayed as plain text, including all tags.

How can I make this input text parsed and behaving like html?

Thanks!

Answer

You’re looking for the ngBindHtml directive:

https://docs.angularjs.org/api/ng/directive/ngBindHtml

<div ng-show="showTab == 'EN'">
    <div class='library-padding'>
        <p ng-bind-html="message"></p>
    </div>
</div>

Leave a Reply

Your email address will not be published. Required fields are marked *