Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape the curly braces in an Angular template? [duplicate]

Tags:

angular

Say I want to display the following string - including the {{ }} - in an Angular 2+ template:

Hello {{name}}, how are you?"

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?
like image 462
AngularChef Avatar asked Nov 30 '22 15:11

AngularChef


1 Answers

There is special built-in attribute ngNonBindable that can be applied like:

<ng-container ngNonBindable>
  Hello {{name}}, how are you?"
</ng-container>

or

<div ngNonBindable>
  Hello {{name}}, how are you?"
</div>

if you have some container

Plunker Example

like image 182
yurzui Avatar answered Dec 04 '22 02:12

yurzui