Removing html code from json feed

Hey all,

I am new to Ionic 2. I have a Wordpress site where I am trying to create an app to show the posts. I have been able to create a json feed and feed that into the app; however, the feed contains html code (

tags).

I have looked through this forum and have not seen the issue discussed.

Is it possible to remove that code? I came across a discussion on DomSanitizer, but I am not sure if that will solve my issue.

Any ideas???

Thank you,
David

It really depends on exactly how the data is formatted and exactly what you want to display.

Hello rapropos,

I am converting a RSS feed from Wordpress to JSON using rss2json.com. I want to display the title and the content on the home page. My plan is to have a different item show there on a daily basis. The title looks fine; however, the content shows the html tags.

Thank you,
David

It would help to see a concrete, precise example of a sample JSON object you are starting with and exactly how you want it to display.

Here is the json feed:

Here is the html:

image

This is the result:

I could not add the Typescript file but I am using ngOnInit to get the posts.

I am not sure if you need all of this, but I would rather give you more than less.

Thank you for your help.

Dave

If the HTML is as vanilla as that example, you might have decent results with:

<div [innerHTML]="item.content"></div>
2 Likes

That gave me an error message:

I tried adding the div before and after it. Both gave me this error message.

I find it very frustrating when people post images instead of text, but look at guarding your template against cases where item is undefined, or make sure in the component that that never happens.

I am very new to this and trying to learn as I try to work through this.

I am not sure what you mean.

This issue has been resolved… I was using an Excerpt plugin that caused the issue. I removed the plugin and now the posts do not show the html code.

You can remove the html tags, in wordpress plugin codes. or you can create a function to remove the html tags when received the posts in your app.

*php code you can use strip_tags. http://php.net/manual/en/function.strip-tags.php
*angularjs you can found examples of the function in google

thx man, i searched for this for a time ago!! :heart_eyes: