2

I'm trying to render html which is saved in json.

It's looks like this html in json is escaped:

{"desc": [{
            "label": "Long Label",
            "label-short": "short Label",
            "text": "Text.<br \/> text <strong class=\"class\"> text <\/strong> foo."
        }]}

I have factory service to get json file.

getFile : function() {
    return $http({
        url: 'data/foo.json',
        method: 'GET'
    })
}

Controller:

   $scope.decodeJson = function(data){
      return Data.decode(data);
   }

    var handleSuccessGetFile = function(data, status) {
         $scope.Desc = data;
    };

    Data.getFile().success(handleSuccessGetFile).error(handleErrorGetFile);

Now i want to render $scope.Desc

<accordion>
    <accordion-group ng-repeat="desc in Desc.desc" heading="{{desc.label}}">
        <p>
            {{decodeJson(desc.text)}}
        </p>
    </accordion-group>
</accordion>

But rendered desc.text is rendered as string not as html, how can i transform it to html?

Based on https://code.google.com/p/jsool/source/browse/jsool-site/js/util/Encoder.js?r=176

I create service decode

   decode: function(string){
                    return string.replace(/&#[0-9]+;/g,function(text,index){
                            return String.fromCharCode(text.match(/[0-9]+/)[0]);
                    });
            }

but it's still rendered as string.

zajca
  • 2,288
  • 4
  • 30
  • 40
  • maybe this question could help you http://stackoverflow.com/questions/9381926/insert-html-into-view-using-angularjs – Bertrand Jun 18 '13 at 14:04

0 Answers0