14

I'll migrate my angularjs application from 1.2.0 to 1.3.0-rc2 and I want to change my code from bindonce to the new one-time binding.IS also used angular-translation. I write the follow code:

<span data-ng-bind="::'COMMENT'|translate" />
<span>{{::'COMMENT'|translate}}</span>
 <img src="shareBlack.png" alt="{{::'SHARE'|translate}}" data-ng-attr-title="::'SHARE'|translate" data-ng-click="startShare()" />

But in Batarang I can see the follow watch expressions:

{{::'SHARE'|translate}} | 3.59% | 17.00ms
::'COMMENT'|translate | 2.95% | 14.00ms

What I did wrong?

EDIT in the previous version 1.2.0 with bindonce I have the following code:

<div class="box-container" bindonce>
    ...
       <span data-bo-text="'FEED_ALLOWED_COMMENTS'|translate"/>
    ...
</div>
Abraham
  • 155
  • 1
  • 6

2 Answers2

14

Just came across this question and the following possible answer while confronted to the same issue:

try :

{{::('COMMENT'|translate)}}

http://plnkr.co/edit/QogrC0bOvX8EYnmQOhpf?p=preview

vgrafe
  • 1,300
  • 1
  • 12
  • 13
  • I just tried the provided plunkr, look at the second binding which follows the above example. remove the two columns and see the value being updated at every time you click. adding the columns back prevent bindings after the first one. – vgrafe Jan 07 '16 at 19:05
1

Now you can do it throw this extension:

translate-once

translate-once directive makes use of the link function and the asynchronous resolver of $translate(). The directive’s link function takes the translation key, looks it up asynchronously with $translate(), and once resolved, writes it to the element.

Salva Bordas
  • 163
  • 1
  • 8