jsonに保存されているhtmlをレンダリングしようとしています。
json のこの html がエスケープされているようです。
{"desc": [{
"label": "Long Label",
"label-short": "short Label",
"text": "Text.<br \/> text <strong class=\"class\"> text <\/strong> foo."
}]}
jsonファイルを取得するファクトリーサービスがあります。
getFile : function() {
return $http({
url: 'data/foo.json',
method: 'GET'
})
}
コントローラ:
$scope.decodeJson = function(data){
return Data.decode(data);
}
var handleSuccessGetFile = function(data, status) {
$scope.Desc = data;
};
Data.getFile().success(handleSuccessGetFile).error(handleErrorGetFile);
$scope.Desc をレンダリングしたい
<accordion>
<accordion-group ng-repeat="desc in Desc.desc" heading="{{desc.label}}">
<p>
{{decodeJson(desc.text)}}
</p>
</accordion-group>
</accordion>
しかし、レンダリングされた desc.text は html ではなく文字列としてレンダリングされます。どうすればそれを html に変換できますか?
https://code.google.com/p/jsool/source/browse/jsool-site/js/util/Encoder.js?r=176に基づく
サービスデコードを作成します
decode: function(string){
return string.replace(/&#[0-9]+;/g,function(text,index){
return String.fromCharCode(text.match(/[0-9]+/)[0]);
});
}
ただし、文字列としてレンダリングされます。