1

i am getting a couple of instances when pulling a json from wordpress api & tumbler on a ng-repeat and the data is coming through as unicode

i think i need to convert to unicode?

examples:

GRAMMY’S
  • should be > GRAMMY’S

     …OR SHOVE 
  • should be …OR SHOVE

any body know the best way to do this ?

Thanks in advance

user3224271
  • 1,214
  • 3
  • 13
  • 22

2 Answers2

1

ended up doing it this way

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

<h2 ng-bind-html="item.title | unsafe"></h2>
Pang
  • 9,564
  • 146
  • 81
  • 122
user3224271
  • 1,214
  • 3
  • 13
  • 22
0

If you control the json, &8217; (html entities) should be \u2019 (unicode). Lets assume you don't control this, it could be interesting to create a function that writes the output to a hidden div, return the html from the hidden div.

Now I must admit angular is not my cup of tea, so basically ...

function convert(output){
    var div = document.createElement('div'),
        text = document.createTextNode(output);

    div.appendChild(text);
    return div.innerHTML;
}

I hope you get the idea. You will render your failing characters in HTML first, to pick them back up immediately and "transformed".

After some digging ... take a look at this post which I believe is your problem.

Community
  • 1
  • 1
Tim Vermaelen
  • 6,869
  • 1
  • 25
  • 39