简体   繁体   English

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

[英]html tags show up in json data angular.js

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 aims to have its smart watch on wrists in China

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,但是只能将实际标签输出为这样的字符串: <div>Apple aims to have its smart watch on wrists in China

Is there any way to either get rid of the HTML altogether or to escape it maybe? 有没有办法完全摆脱HTML或逃脱它?

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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM