view raw
splincode web-developer splincode web-developer - 6 months ago 42
AngularJS Question

How replace html in template angular

I have a variable that stores data = { decription: 'text <br> info \n' };

In html I bring it

<div> {{ ::$ }} </div>

However, the text is displayed without any formatting, but I would like it to be like html, how to fix it?


Basically to use ng-bind-html you need to tell angular that the HTML content string is trusted to know more about this you can refer this article in angular docs,so to that add below code in your JS

$ =   $sce.trustAsHtml('text <br> info \n');

But simply this line will throw you an error saying 'unknown provider' to use that you need to have angular-sanitize.js in order to inject $sce in your controller and ngSanitize in your angular module like var app = angular.module('app',['ngSanitize']);

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

$ = {};
$ =   $sce.trustAsHtml('text <br> info \n');
<script data-require="angularjs@1.5.8" data-semver="1.5.8" src=""></script>
  <script src="//"></script>

<div ng-app="app" ng-controller="Ctrl"> 
<div ng-bind-html="storage.description"></div>