0

I am working with Angular 2 and C#, SQL Server (database). I have a scenario where some HTML string is coming from database which contains the HTML tags or special characters like- (> , < & etc).

So when it's coming from database the special character's are coming in encoded format. But I wanted to decode it in it's actual content in TypeScript file. Below is the example of my original string-

 if > 10

And it's showing in UI as below-

if  &gt; 10

I am using below code in HTML-

<div class="bold-text">{{vm.Name}}</div>

Can anyone suggest how we can decode it in TypeScript or Angular 2 .

1
  • try <div [innerHTML]="vm.Name"></div> Commented Jun 29, 2018 at 5:55

1 Answer 1

1

You need to use ng-bind-html directive

 <p ng-bind-html="vm.Name"></p>
Sign up to request clarification or add additional context in comments.

3 Comments

@Saneetharan, it's working like this <p ng-bind-html="vm.Name | renderHTML"></p>
But I am not sure what is the diff between ng-bind-html and ng-bind-html | renderHTML ?
what do you mean

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.