Jesse Buitenhuis
Jesse Buitenhuis

Reputation: 670

Nesting quotes in Angular expression

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?

Upvotes: 5

Views: 4931

Answers (2)

Pankaj Parkar
Pankaj Parkar

Reputation: 136174

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.

Upvotes: 4

Jesse Buitenhuis
Jesse Buitenhuis

Reputation: 670

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

The format that works is:

placeholder="{{ 'PLURAL' | translate:{gender:'male'}:'messageformat' }}"

Upvotes: 1

Related Questions