0

I have some angular expressions that contain data coming from a database. Some of this data contain HTML tags in the database and should be decoded as such in the HTML.

Javascript function:

vm.showTechnicalSupport = function () {
        $http.get('Navigation/GetTechSupportInformation').success(function (data) {
            vm.techSupportHours = data.techSupportHours;
        })

    }

HTML:

<span>{{ vm.techSupportHours}}</span>

The problem is techSupportHours is displaying raw HTML tags instead of rendering markup. For example, there are br tags being displayed visibly on the page. Is there a way to modify my angular expression to decode this data?

1

1 Answer 1

2

There is a directive called ng-bind-html which is what you are looking for. So just change your html template to be:

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

2 Comments

Nothing is displaying when I use this directive.
@noclist Pleas ensure you also include angular-sanitize, it's part of Angular but not included in the core angular.js. You can see a working example here: plnkr.co/edit/oS492EJ0OujuC9M0Vt1V?p=preview

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.