Abdulla khan
Abdulla khan

Reputation: 768

Angularjs: Latin / Spanish character showing as junk character

JS:

$scope.test = 'Amidación';

HTML:

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

OUTPUT:

Amidaci�n   

Issue: I am getting the latin character ó in output as � junk character, i tried ngsanitize also but it didn't resolved. Any idea how it can render correctly ?

Note: Can't convert the latin character into ascii or hexadecimal because it is a Json data.

Upvotes: 1

Views: 1106

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

Basically you need to sanitize your text using $sce, for that you needto make that html as trusted using $sce.trustAsHtml method.

Code

angular.module('app', [])
  .controller('MainController', ["$scope", "$http", '$sce',
    function($scope, $http, $sce) {
      $scope.test = $sce.trustAsHtml('Amidación');
    }
  ]);

Working Plunkr

Update

More better way would be you could create your own filter that can be act as reusable component

Markup

<span ng-bind-html="test | unsafe"></span> 

Filter

app.filter('unsafe', function($sce) {
    return $sce.trustAsHtml;
}); 

Upvotes: 1

Related Questions