Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 685
Felix Avatar asked Feb 11 '16 11:02

Felix


People also ask

How do I translate words into components TS files?

component. ts file we need to import a translate service from @ngx-translate/core package inject the service in constructor and use it after changing the language. Now create a folder inside assets, name it 'translate,' inside of it create a json file.

Which one of the following angular CLI commands will extract the marked text for translation in the application and create a translation source file?

After you prepare a component for translation, use the extract-i18n Angular CLI command to extract the marked text in the component into a source language file.

What is translate pipe in angular?

The service also contains a method called translate. It is later called by the pipe to get the translation for a specific key. It always uses the language specified in the 'language'-variable of the service, to lookup the translation. That's it.


1 Answers

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.

like image 57
Outside_Box Avatar answered Sep 25 '22 11:09

Outside_Box