Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One-time binding with filter

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>
like image 584
Abraham Avatar asked Sep 18 '14 10:09

Abraham


People also ask

What does :: mean in angular?

It means it's used to achieve one time binding. Example. angular.

Which is not recommended in AngularJS?

It is tempting to do too much work in the AngularJS controller. After all, the controller is where the view first has access to JavaScript via $scope functions. However, doing this will cause you to miss out on code sharing across the site and is not recommended by AngularJS documentation.

What is the correct syntax to write an expression in angular?

AngularJS expressions can be written inside double braces: {{ expression }} . AngularJS expressions can also be written inside a directive: ng-bind="expression" .

Which directive can be used to write AngularJS expressions?

Answer: C is the correct option. The ng-app directive is used to initialize the AngularJS application.


2 Answers

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

like image 194
vgrafe Avatar answered Oct 27 '22 19:10

vgrafe


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.

like image 45
Salva Bordas Avatar answered Oct 27 '22 18:10

Salva Bordas