110

I want the user to see double curly braces, but Angular binds them automatically. This is the opposite case of this question where they want to not see curly braces used for binding when the page is loading.

I want the user to see this:

My name is {{person.name}}.

But Angular replaces {{person.name}} with the value. I thought this might work, but angular still replaces it with the value:

{{person.name}}

Plunker: http://plnkr.co/edit/XBJjr6uR1rMAg3Ng7DiJ

Community
  • 1
  • 1
Jason Goemaat
  • 28,692
  • 15
  • 86
  • 113
  • If you are willing to go with another delimiter altogether (such as `[[ ]]`): http://stackoverflow.com/questions/12923521/angular-js-custom-delimiter – Thilo Jun 01 '13 at 01:06
  • 2
    Thanks, I saw that but the whole point is really for a sample page showing how the braces work and I want viewing the source to be able to look exactly like what's on the page showing the sample if that makes sense. – Jason Goemaat Jun 01 '13 at 01:08
  • possible duplicate of [Prevent double curly brace notation from displaying momentarily before angular.js compiles/interpolates document](http://stackoverflow.com/questions/12866447/prevent-double-curly-brace-notation-from-displaying-momentarily-before-angular-j) – Maxime Lorant Nov 09 '14 at 16:13
  • 1
    @MaximeLorant That is a completely different issue to do with preventing the momentary display of curly braces when the page is loading, this question is about getting them TO display even after the page has loaded and to prevent angular from binding them. – Jason Goemaat Nov 11 '14 at 03:14

8 Answers8

160
<code ng-non-bindable>{{person.name}}</code>

Documentation @ ngNonBindable

Mike Pugh
  • 6,787
  • 2
  • 27
  • 25
31

Edit: adding \ slash between brackets inside the quotes works

{{  "{{ person.name }\}"   }}  

this too .. by passes angular interpreting

{{ person.name }<!---->}

this too ..

{{ person.name }<x>} 

{{ person.name }<!>}
bh_earth0
  • 2,537
  • 22
  • 24
14

In our case we wanted to present curly brackets in a placeholder, so they needed to appear inside an HTML attribute. We used this:

 <input placeholder="{{ 'Hello {' + '{person.name}' + '}!' }}" ...>

As you can see, we are building up a string from three smaller strings, in order to keep the curly braces separated.

'Hello {' + '{person.name}' + '}!'

This avoids using ng-non-bindable so we can continue to use ng- attributes elsewhere on the element.

joeytwiddle
  • 29,306
  • 13
  • 121
  • 110
9

Updated for Angular 9

Use ngNonBindable to escape interpolation binding.

<div ngNonBindable>
  My name is {{person.name}}
</div>
Matt
  • 33,328
  • 25
  • 83
  • 97
4

I wanted single brackets across text and the above solutions didn't work for me. So did want the Angular recommended.

Angular Version: 5

Required Text: My name is {person.name}.

<span>My name is {{'{'}}person.name{{'}'}}.</span>

I hope it helps someone.

bhavya_karia
  • 760
  • 1
  • 6
  • 12
3

Use ng-non-bindable in container, this is effective on all element inside here container.

<div ng-non-bindable>
  <span>{{person.name}}</span>
  <img src="#" alt="{{person.name}}">
  <input placeholder="{{person.name}}">
</div>
Nabi K.A.Z.
  • 9,887
  • 6
  • 59
  • 81
3
<span>{{</span>{{variable.name}}<span>}}</span>
EscapeNetscape
  • 2,892
  • 1
  • 33
  • 32
0

From Angular compiler:

Unexpected character "EOF" (Do you have an unescaped "{" in your template? Use "{{ '{' }}") to escape it.)

So in the original question - you would end up with:

My name is {{ '{' }}{{ '{' }}person.name{{ '}' }}{{ '}' }}
user369142
  • 2,575
  • 1
  • 21
  • 9