0
votes

Certain chars and text after that gets rejected when using ng-bind-html along with $sce.trustAsHtml. Any Ideas on taclking this issue?

Controller

angular.module('myApp', []).controller('IndexController', ['$scope', '$sce', function($scope, $sce){
  $scope.text= $sce.trustAsHtml('TEST>19 XYZ </= This is not showing up in ng-bind-html />');
}]);

HTML
<!DOCTYPE html>
<html ng-app="myApp">

<head>
  <script data-require="angular.js@*" data-semver="1.3.8" src="http://code.angularjs.org/1.3.8/angular.js"></script>
  <script src="script.js"></script>
  <link rel="stylesheet" type="text/css" href="style.css">  
</head>

<body ng-controller="IndexController">
  <input style="width:100%" type="text" ng-model="text">
  <div ng-bind-html="text"></div>
</body>
</html>

plunker http://plnkr.co/edit/kjtNXYzPCMS3Q3OirwYZ?p=preview

1
Maybe because its HTML?Richard Cotrina
This is invalid html, the < and > should be encoded as html entities : &gt; &lt;Renan Le Caro
I understand that is an invalid html, however I am trying to figureout a way to display that as it is in the page using ng-bind-html thought.user1288411

1 Answers

1
votes

This is invalid html, the < and > should be encoded as html entities : &gt; &lt;

If you just put this html in a page, the display is the same (please run the very simple snippet below). The browser just doesn't know what to do with this tag.

TEST>19 XYZ </= This is not showing up in ng-bind-html />