5

In .js files triple nested quotes ("one'two"three"'") can be escaped (see this post) and in HTML this can also be achieved using character references (see this post). I have a problem achieving this in an AngularJS expression in my template.

I need to put this:

{{ 'PLURAL' | translate:"{ GENDER: 'male' }":"messageformat" }}

Into a placeholder element:

<input placeholder="{{ 'PLURAL' | translate:"{ GENDER: 'male' }":"messageformat" }}">

How should I escape the quotes to make it work?

Community
  • 1
  • 1
Jesse Buitenhuis
  • 670
  • 4
  • 11

2 Answers2

4

Answer would be put { GENDER: 'male' } in some scope variable then do use that inside your interpolation directive expression, that will simplify your escaping more better.

Markup

<div ng-init="maleFilter = { GENDER: 'male' }">
   <input ng-attr-placeholder="{{ 'PLURAL' | translate: maleFilter : 'messageformat' }}">
<div>

Hope this could help you, Thanks.

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
1

For future reference. These Angular Translate docs were confusing to me.

The format that works is:

placeholder="{{ 'PLURAL' | translate:{gender:'male'}:'messageformat' }}"
Jesse Buitenhuis
  • 670
  • 4
  • 11