tags saved in bd being printed as text

1
Hello, I am printing a saved value in a mysql text field, which contains 'p' tags in its composition, the problem is that it is printing these tags as text and not as html, does anyone know what the problem would be? I'm using angular to print the bank's values.

    
asked by anonymous 14.04.2016 / 21:30

1 answer

3

Use the ng-bind-html directive to display HTML content:

<span ng-bind-html="variavel"></span>

If the $ sce service is enabled, you must mark the HTML content as trusted. In this case, implement a filter that will be concatenated to pipeline :

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

app
.filter('trustAs', function($sce) {
        return function (input, type) {
            if (typeof input === "string") {
                return $sce.trustAs(type || 'html', input);
            }
            return "";
        };
    })
.controller('SampleController', function ($scope) {
  $scope.variavel ='<b>teste</b> de HTML';
});
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.9/angular-resource.js"></script>
<div ng-app="sampleApp">

  <div ng-controller="SampleController">
    
    <span ng-bind-html="variavel | trustAs"></span>
    
  </div>
</div>

Sources:
ngBindHtml - AngularJS directive components
link

    
14.04.2016 / 21:40