How do I combine an if/else expression with angular translate inside an attribute?
Asked Answered
S

1

10

I'm using an if/else expression and a translation of the possible values inside the placeholder-Tag of an HTML input-element. It obviously doesn't work this way, because of the 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 the single/double-quotes accordingly or is there even a more elegant solution?

Succussion answered 11/2, 2016 at 11:3 Comment(2)
I'm not sure but you could try {{(constraint ? "TERM_A" : "TERM_B") | translate}}Purify
Yes, that works: placeholder="{{ (constraint ? 'TERM_A' : 'TERM_B') | translate }}" ,thanks!Succussion
W
10

Proper way:

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

Another sample:

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

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

Walczak answered 20/12, 2017 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.