splash27
splash27

Reputation: 2107

How to process some HTML-tags (not all) from strings?

I am using AngularJS.

I am facing an problem with AngularJS and problem is that, I received a string like from server and assigned it to model "<p>Hello<\/p><p>to all!<\/p>". So, the result I can see on the page is <p>Hello</p><p>to all!</p>. I want <p>-tags be applied like this:

<p>Hello</p><p>to all!</p>

How can I get this using Angular? I also need to use some other tags like <b>,<ul> and others. But dangerous tags like <script> and <style> should be rejected. Also markup tags such as <table>, <div> should be avoided.

And this is my markup:

    <div flex layout="row">
        {{instance.description}}
    </div>

Upvotes: 0

Views: 59

Answers (2)

Tarun Garg
Tarun Garg

Reputation: 132

You have to use ng-bind-html along with ngSanitize for this kind of use cases.

A perfect tutorial of how to use these is this, Do spend some time checking it out.

Upvotes: 1

Ron Dadon
Ron Dadon

Reputation: 2706

Use ng-bind-html directive

<div flex layout="row" ng-bind-html="instance.description">
</div>

You need to have ngSanitize module in your application to protect against malicious code

Upvotes: 0

Related Questions