0

What is the difference between adding translation in these two ways:

<div class="row" translate="{{::'newvisitormodal-bannerimage'}}">


<div class="row">{{::'newvisitormodal-bannerimage' | translate}}</div>

And how to used first approach in case of placeholder like this:

<input id="txtresetPassword" type="password" placeholder="{{::'reset-password-enternewpassword' | translate}}" >
Amna
  • 603
  • 7
  • 30

2 Answers2

0

In first case, translate is a directive. In a second it is a filter.

So main difference is about how result value will be evaluated. In a first case, it will be done with link functin and then will reevaluate according to the directive logic. In a second case, this value will pass to the filter and will be reevaluated every digest. But in both case you use one time binding. So your value will never change. This means nothing to filter, because it will be invoked every digest. But may have sence for directive, because it can have more "smart" logic

Drag13
  • 5,859
  • 1
  • 18
  • 42
  • I am facing an issue of not converting into translation at a random time in the second case. So I am confused, is it some asynchronous behavior. – Amna Jun 14 '16 at 09:12
  • Remove one time binding with filter and I hope all will be great. Thats why i do not like filters – Drag13 Jun 14 '16 at 09:14
  • I am not getting this. Why remove one-time binding? And what if I used first method everywhere.? Why second method is provided.Like in which scenarios should i used second method – Amna Jun 14 '16 at 09:16
  • Because... First of all you should now that filters fired evry digest. If there are several digests then filter will fire several times. When undefined value returns to one time binding, then $watch, created with one time binding is not deregistrate. But when filter returns another value, watch will be killed. And when real value comes, it will not be rendered. Smth like this. – Drag13 Jun 14 '16 at 09:21
  • How can i used first approach in case of placeholder...See my edited question – Amna Jun 14 '16 at 09:27
  • Try to remove one time binding from expression in attribute – Drag13 Jun 14 '16 at 09:29
0

In the first one translate is used as a directive which is a linked function which return the value as the logic mentioned in directive's implementation.

In the second approach the newvisitormodal-bannerimage will be the key for the translation. It get the translated value from the translation JSON.

But the recommended approach is the first one,since the second approach has been deprecated.

This question has been already answered as I understand

See this

<input placeholder="Please Enter Your Password" translate translate-attr-placeholder="text" translate-value-browser="{{reset-password-enternewpassword}}">

https://stackoverflow.com/a/30116300/3156647

Community
  • 1
  • 1
tarzanbappa
  • 4,930
  • 22
  • 75
  • 117
  • I am facing an issue of not converting into translation at a random time in the second case. So I am confused, is it some asynchronous behavior. – Amna Jun 14 '16 at 09:21
  • Can I get a reference where it is depreciated? – Amna Jun 14 '16 at 09:21
  • Using translate filter is great, but using translate directive is better. It turned out that having too many filters in a view sets up too many watch expressions, which is why angular-translate also provides a directive to translate your contents in view layer. – tarzanbappa Jun 14 '16 at 09:28