question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng-show with translate-values

See original GitHub issue

Subject 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:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
knallicommented, Aug 19, 2018

@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-compile only 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-values aren’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.

variable = 'test'

// translation interpolation of '<span ng-show="\'{{variable}}\'">'
<span ng-show="\'test\'">

// AJS template interpolation of the string above (no access to the values any more)
<span ng-show=truthy>
0reactions
charlie-ablettcommented, Aug 19, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found