Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 995
Jesse Buitenhuis Avatar asked Mar 07 '15 19:03

Jesse Buitenhuis


People also ask

Is it common to use ng-init in angular?

Using ng-init is not very common. You will learn a better way to initialize data in the chapter about controllers. Like JavaScript expressions, AngularJS expressions can contain literals, operators, and variables. Unlike JavaScript expressions, AngularJS expressions can be written inside HTML.

What is an expression in AngularJS?

AngularJS expressions are much like JavaScript expressions: They can contain literals, operators, and variables. If you remove the ng-app directive, HTML will display the expression as it is, without solving it: You can write expressions wherever you like, AngularJS will simply resolve the expression and return the result.

What is @AngularJS?

AngularJS will resolve the expression, and return the result exactly where the expression is written. AngularJS expressions are much like JavaScript expressions: They can contain literals, operators, and variables.

How to get proficiency level from a nested component in angular?

The nested component will take the ‘Proficiency In Angular’ column values as input and give us output as a proficiency level. We write the following code in rating.component.ts,


1 Answers

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.

like image 100
Pankaj Parkar Avatar answered Sep 30 '22 06:09

Pankaj Parkar