1

I want to display my editor value from MySQL database. when I am displaying data with angularJS then it is showing text with html tag.

HTML Code:-

<pre>
  {{x.description}}
</pre>

Here I am getting output:-

<p>Hello India</p><br/>
<p>List Of State</p><br/>
<ol><br/>
<li>Karnataka</li><br/>
<li>Bihar</li><br/>
<li>Delhi</li><br/>
</ol>

But I want to result Like this:-

Hello India 
List of State
  1. Karnataka
  2. Bihar
  3. Delhi
3
  • @vivek_23 not working Commented Jul 1, 2019 at 8:21
  • My bad. I thought you were using angular CLI. Commented Jul 1, 2019 at 8:44
  • @vivek_23 I am using angularJS 1.x Commented Jul 1, 2019 at 9:01

1 Answer 1

3

This can be done by using ng-bind-html

var app = angular.module("myApp", ['ngSanitize']);
app.controller("myCtrl", function($scope) {
    $scope.myText = `<p>Hello India</p><br/>
<p>List Of State</p><br/>
<ol><br/>
<li>Karnataka</li><br/>
<li>Bihar</li><br/>
<li>Delhi</li><br/>
</ol>`;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular-sanitize.js"></script>


<div ng-app="myApp" ng-controller="myCtrl">
<pre>
 <div ng-bind-html="myText"></div>
</pre>
</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.