简体   繁体   中英

Unable to remove html tags from response JSON

Hi I am new to AngularJS. I am having a problem parsing JSON data to proper format. Actually the JSON response itself returned HTML format data (it contains HTML tags like &lt,;BR,> etc). If I check the response in browser it returns fine, but in device(TAB,MOBILE) the HTML tags are also getting appended. I am using AngularJS to bind the JSON response to DOM. Is there any way to simply ignore HTML tags in JQuery or in AngularJs? At the same time I don't want to remove the HTML tags as they are necessary to define "new line", "space", "table tag" etc.

A sample response I am getting is like:

A heavier weight, stretchy, wrinkle resistant fabric.<BR><BR>Fabric Content:<BR>100% Polyester<BR><BR>Wash Care:<BR> 

If I apply the binding using {{pdp.desc}} , the HTML tags are also getting added. Is there any way to accomplish this?

I have added ng-bind-html-unsafe="pdp.desc", but still "BR" tags r coming.

可以使用regix表达式删除无用的html标签,试试这个

str.replace(/<\/?[^>]+>/gi, '')

尝试使用三对括号{{{pdp.desc}}}在Handlebars中它可以工作,可能在你的情况下。

Use JS HTML parser

var pattern = @"<(img|a)[^>]*>(?<content>[^<]*)<";
var regex = new Regex(pattern);
var m = regex.Match(sSummary);
if ( m.Success ) { 
  sResult = m.Groups["content"].Value;

courtesy stackoverflow.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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