AngularJS convert unicode html ng-repeat

1.4k views Asked by At

I have an issue with AngularJS. I have this code in my template to display a list of users:

<ion-list>
  <ion-item class="item-avatar" ng-repeat="x in filtered = ( users | filter:query)" href="#/user/{{x.ID}}">
    <img src="http://m.myapp2go.de/ionic/todo/www/img/ionic.png" />
    <h2>{{x.Name1}}</h2>
    <p>
      {{x.Name2}} - ({{x.Phone}})
    </p>
  </ion-item>
</ion-list>

I get my data in a $http.get-request. JSON is unicoded, e.g.: "Name1":"• RS's •"

{"items":[{"ID":"10033","UserID":"RSC","Passwort":"66676e6567313233","Name1":"&bull; RS&#039;s &bull;","Name2":"Schumacher","NameZusatz":"RSC", ......
},

How can i display Name1 {{x.Name1}} in the right way in my template? In my controller i have a function which is decoding a string in the correct way using jquery.

$scope.decodeHTML = function(html_code) {
    if (html_code) {
      return $('<div />').html(html_code).text();
    } else {
      return '';
    }
};

Do i have to change the $scope-data with the converted string or are there other possibilities? I tried everything with ng-bind-html="expression" but no success.

1

There are 1 answers

0
Ralf Bordé On

I have got the solution:

  // decode unicoded html
$scope.decodeHTML = function(x){
        return $sce.trustAsHtml(x);
    };

In my template :

<h2 ng-bind-html="decodeHTML(x.Name1)"></h2>

That's it.