Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render text into HTML in AngularJS

I have a variable in a scope with some HTML content. I want to render it as HTML on the webpage, but in my case it displays as full text. Can anyone help me?

This is my code:-

//contoller.js

$scope.message = '<b><i>result has been saved successfully.</i></b>';

//demo.html

<p ng-bind="message"></p>
like image 732
Surjeet Bhadauriya Avatar asked Dec 03 '22 15:12

Surjeet Bhadauriya


1 Answers

You need to inject $sce service into your controller or Directive etc. and use $sce service like this:-

$scope.Message = $sce.trustAsHtml("<b><i>result has been saved successfully.</i></b>");

And bind this in your HTML page e.g;

<p ng-bind-html = "Message"></p>
like image 159
KP Chundawat Avatar answered Dec 22 '22 13:12

KP Chundawat