0

I am using AngularJS v1.7.9

In my database I have person name value stored as <i>FirstName</i> Last Name When I use this value using interpolation as {{person.name}} I see it as <i>Alexandra</i> Golfi

Why AngularJS can not read the html tag? is there a way I can still display first name in italic style while storing first name and last name in the same data base column

Thank you

4
  • not sure of my answer so I'm putting a comment but IIRC you need to use {{person.name | html}} Commented Aug 17, 2020 at 12:12
  • @jonatjano I tested it is coming as {{person.name | html}} Commented Aug 17, 2020 at 12:18
  • That is due to Angular Dom sanitizer, it sanitizer inputs and escapes html characters use the html pipe Commented Aug 17, 2020 at 12:19
  • @Ainz-sama which filter to use that reads <i> tag? Commented Aug 17, 2020 at 12:22

1 Answer 1

1

The ng-bind-html directive is a secure way of binding content to an HTML element.

When you are letting AngularJS write HTML in your application, you should check the HTML for dangerous code. By including the "angular-sanitize.js" module in your application you can do so by running the HTML code through the ngSanitize function. syntax:

<element ng-bind-html="expression"></element>

Example :

<span ng-bind-html="person.name"></span>

Reference:

https://docs.angularjs.org/api/ng/directive/ngBindHtml

https://www.w3schools.com/angular/ng_ng-bind-html.asp

Sign up to request clarification or add additional context in comments.

Comments

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.