如何在Angular模板中转义花括号? [英] How to escape the curly braces in an Angular template?
本文介绍了如何在Angular模板中转义花括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我想在Angular 2+模板中显示以下字符串-包括{{ }}
-
Say I want to display the following string - including the {{ }}
- in an Angular 2+ template:
Hello {{name}}, how are you?"
NB.整个字符串将被硬编码,而不是来自变量.
NB. The whole string will be hard-coded, it won't come from a variable.
逃避花括号以使其不被视为插值的最佳方法是什么?
What's the best way to escape the curly braces so that they're not considered an interpolation?
我有一些可以使用的东西,但看起来并不干净:
I have something that works but it doesn't look super clean:
Hello {{ '{{' }}name}}, how are you?
推荐答案
有一个特殊的内置属性ngNonBindable
可以像这样应用:
There is special built-in attribute ngNonBindable
that can be applied like:
<ng-container ngNonBindable>
Hello {{name}}, how are you?"
</ng-container>
或
<div ngNonBindable>
Hello {{name}}, how are you?"
</div>
如果您有一些容器
Plunker Example
这篇关于如何在Angular模板中转义花括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文