How to combine if / else expression with angular translate inside attribute?

I use the if / else expression and translate the possible values ​​inside the placeholder-Tag of the HTML input element. Obviously this does not work, due to nested double quotes inside the placeholder tag:

<input type="number" placeholder="{{constraint ? '{{"TERM_A" | translate}}' : '{{"TERM_B" | translate}}'}}" ng-model="" required autocapitalize="none" autocorrect="off" /> 

How do I set single / double quotes accordingly or is there an even more elegant solution?

+5
source share
1 answer

The right way:

  <input type="number" placeholder="{{ (constraint ? 'TERM_A' : 'TERM_B') | translate }}" ng-model="" required autocapitalize="none" autocorrect="off" /> 

One more example:

  label="{{ (detailsTriggered ? 'ui.showDetails' : 'ui.hideDetails') | translate}}" 

Beware of the "[]" braces, quotation marks, and apostrophes.

+1
source

Source: https://habr.com/ru/post/1242763/


All Articles