在Angular 2绑定中显示HTML特殊字符? [英] Display HTML special characters in Angular 2 bindings?

查看:122
本文介绍了在Angular 2绑定中显示HTML特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像{{foo}}这样的普通绑定,它将foo的值显示为HTML中的文本.来自服务器的文本为"R&D".我需要将其显示为"R& D".有帮助吗?

I have a normal binding like this {{foo}} and it displays foo's value as text in the HTML. The text that comes from the server is "R&D". I need this to display as "R&D". Any help?

推荐答案

{{}}用于字符串绑定.

使用属性绑定到innerHTML来正确显示这些字符.

Use attribute binding to innerHTML instead to get these characters displayed correctly.

<div [innerHTML]="foo">

有关更多详细信息,请参见 https://stackoverflow.com/a/41089093/217408 .

See https://stackoverflow.com/a/41089093/217408 for more details.

这篇关于在Angular 2绑定中显示HTML特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆