1

I have a data that contains HTML (for exemple I have <b>XXXX</b>) and I would like to display it as:

XXXX

I want this to be rendered as bold when it gets displayed on view.

How can I do that?

2 Answers 2

3

You can use ng-bind-html that exaclty do what you are looking for.

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

app.controller('MainCtrl', function ($scope) {
    $scope.text = "<b>XXXX</b>";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.1/angular-sanitize.min.js"></script>

<div ng-app="myApp" ng-controller="MainCtrl">
    <div ng-bind-html="text"></div>
</div>


Note that you will have to include ngSanitize in your dependencies to be able to use it.

Test it on JSFiddle!

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

Comments

0

In AngularJS you can use ng-bind-html to render the html on view.

it will make your content XXXX bold.

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.