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?
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.
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.
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.
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,
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With