简体   繁体   English

AngularJS 未在插值中读取 html 标签

[英]AngularJS not reading html tag in interpolation

I am using AngularJS v1.7.9我正在使用 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在我的数据库中,我将人名值存储为<i>FirstName</i> Last Name当我使用插值作为{{person.name}}使用此值时,我将其视为<i>Alexandra</i> Golfi

Why AngularJS can not read the html tag?为什么 AngularJS 无法读取 html 标签? 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谢谢

The ng-bind-html directive is a secure way of binding content to an HTML element. ng-bind-html 指令是一种将内容绑定到 HTML 元素的安全方式。

When you are letting AngularJS write HTML in your application, you should check the HTML for dangerous code.当您让 AngularJS 在您的应用程序中写入 HTML 时,您应该检查 HTML 中的危险代码。 By including the "angular-sanitize.js" module in your application you can do so by running the HTML code through the ngSanitize function.通过在应用程序中包含“angular-sanitize.js”模块,您可以通过 ngSanitize function 运行 HTML 代码来实现。 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://docs.angularjs.org/api/ng/directive/ngBindHtml

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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