2

I am a beginner in javascript trying to learn AngularJS. I have a problem. I am confused how to create a helper for parsing / decode html result from JSON API e.g `

summary: "\u003Cdiv\u003E\u003Cdiv\u003E \u003Cp\u003EDiantara hikmahnya adalah, wanita semakin disimpan, semakin terhormat. Yang berarti kehormatan pula bagi suaminya\u003C/p\u003E \u003Cdiv\u003E Artikel Terkait:\u003Col\u003E \u003Cli\u003E\u003Ca

from this API URL : http://api.situssunnah.com/api/articles.json

I tried to use .replace method but didn't work.

ikhsannetwork
  • 103
  • 2
  • 6
  • 1
    Parsing HTML: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – William Barbosa Jul 16 '14 at 15:46

1 Answers1

-1

Hi plese see solution here http://jsbin.com/puyeluti/3/edit

1.replace all Unicode characters

angular.forEach($scope.articles, function (article) {
        article.summary = article.summary.replace(/\\u003C/g, "<")
                                    .replace(/\\u003E/g, '>')
                                    .replace(/\n/g, '')
                                    .replace(/\\u0026/g,'&');
        });

2.Use ng-bind-html directive

<p ng-bind-html="i.summary"></p>
sylwester
  • 16,498
  • 1
  • 25
  • 33
  • I use Yeoman for scaffolding, grunt and bower. it's automatically include sanitize. i use ngResource in service like $resorurce(urlAPI); this implemented in jsbin : http://jsbin.com/puyeluti/2/edit Sorry for bad english – ikhsannetwork Jul 17 '14 at 08:51
  • @ikhsannetwork i've update answear please see http://jsbin.com/puyeluti/3/edit – sylwester Jul 17 '14 at 09:12
  • thank you. i use filter for reusable replacing regex in articles summary and article content. http://jsbin.com/puyeluti/10/edit http://jsbin.com/puyeluti/19/edit – ikhsannetwork Jul 20 '14 at 22:53