ng-show with translate-values
See original GitHub issueSubject of the issue
Sorry if this has already been shown, but I can’t find it anywhere.
I’m using directives (ng-show, ng-hide, ng-if, etc) in translate strings, and it’s not working for me. I’m using translate-compile.
Your environment
- version of angular-translate 2.15.2
- version of angular 1.5.3
- which browser and its version Chromium | 68.0.3440.75 (Official Build) (64-bit)
Steps to reproduce
Run the plunkr
Expected behaviour
I should see “Variable is 1.2.3.”
Actual behaviour
Even when variable is set, Variable is missing! appears
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ngShow - AngularJS: API
The ngShow directive shows or hides the given HTML element based on the expression provided to the ngShow attribute. The element is shown...
Read more >Sanitize some translate values but not others - Stack Overflow
I have a angular-translate directive that takes arguments, which are mixed. Some are user-generated, others are HTML that must be compiled (with ...
Read more >So you thought you were safe using AngularJS. . . . Think again!
csp.css in the HTML for ngShow and ngHide directives to work. Angular Setting. Code. Angular Behavior ... translateValues = {name: $routeParams.name};.
Read more >Angular Translation - Plunker
translateValues :void 0,i=g. ... observe("translateValues",function(a){a&&b. ... The built in directives * `ngRepeat`, `ngInclude`, `ngSwitch`, `ngShow`, ...
Read more >angularjs-slider - npm
ng-show -example: http://jsfiddle.net/ValentinH/nzL6ax43/ ... Use this if you want to translate values displayed on the slider.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@charlie-ablett You have to escape the interpolation
'<span ng-show="variable">…'=>'<span ng-show="\'{{variable}}\'">…'.See also working demo: https://plnkr.co/edit/64C3QrKJJGZ9KKhoRvZs?p=preview
The reason for this:
translate-compileonly compiles the translation which means basically you have access to the actual current context (scope). Said this,<span ng-show="app.someVariable">would work, however, that would not be probably useful.The
translate-valuesaren’t the scope of the compilation interpolation, but of the translation interpolation (one step before).In a nutshell: The interpolation step must render the result (which means it will not work with complex structures because of serialization) and the result of this must be escaped probably for AngularJS.
@knalli Thanks for your attention so far. On my project and on the plunkr above (https://plnkr.co/edit/Pacl7EXx3dgVrGX2rDYj?p=preview) I’ve updated the version of angular-translate, angular-sanitize and angularjs to latest. The issue persists - would you be able to take look again?
Many thanks.