html标签显示在json数据angular.js中

时间:2021-03-09 19:41:41

I am busy making an app in Ionic and I am running into a problem with a JSON string that contains HTML.. The JSON is getting pulled off a Joomla site and seems to be retaining the HTML tags and special chars.. The string looks like this: "<div>Apple aims to have its smart watch on wrists in China

我正在忙着在Ionic中创建一个应用程序,我遇到了一个包含HTML的JSON字符串的问题.JSON从Joomla网站上撤下来,似乎保留了HTML标签和特殊字符..字符串看起来像这个:“< div> Apple的目标是将其智能手表放在中国的手腕上

I looked around and found that I should use ng-bind-html but that only outputs the actual tags as strings like this: <div>Apple aims to have its smart watch on wrists in China

我环顾四周,发现我应该使用ng-bind-html,但只输出实际的标签作为这样的字符串:

Apple的目标是将智能手表放在中国的手腕上

Is there any way to either get rid of the HTML altogether or to escape it maybe?

有没有办法可以完全摆脱HTML或者逃避它?

1 个解决方案

#1


1  

You could pass the HTML text through .replace to get rid of the tags

您可以通过.replace传递HTML文本以删除标记

var yourstring = "&lt;div&gt;Your text content&lt;/div&gt;";
yourstring = yourstring.replace(/&lt;[^&]*&gt;/g, '');
// yourstring is now "Your text content"

#1


1  

You could pass the HTML text through .replace to get rid of the tags

您可以通过.replace传递HTML文本以删除标记

var yourstring = "&lt;div&gt;Your text content&lt;/div&gt;";
yourstring = yourstring.replace(/&lt;[^&]*&gt;/g, '');
// yourstring is now "Your text content"