angularjs - How to use angular translate directive with limitTo filter -


i using angular translate directive in application. translating key returns string.

<div translate="translation_key"></div> 

suppose got translation in string form apply online course.

now want string limit 12 characters thisapply online....

so have done this

<div {{translate="translation_key | limitto:12 }}"></div> 

but not correct how can use limitto filter when expression coming translation itself.

also use of translate-values , translate-compile.

limiting string limitto filter

{{ limitto_expression | limitto : limit : begin}}

https://docs.angularjs.org/api/ng/filter/limitto

{{ "my string long" | limitto: 9 }} 

which output:

my string 

or use following approach (not using translate directive.

<span>{{translation_key|translate|limitto:9}}</span> 

https://angular-translate.github.io/docs/#/guide/04_using-translate-filter

about other question regarding angular-translate directive.

the translate directive expects optional translate-values attribute can use pass values through it. have combine directive translate-values attribute.

you can pass either object literal string, expression, or, if value dynamic, interpolation directive. whatever pass in, gets internally evaluated , parsed translate filter, comes out plain old javascript object gets passed $translate service.

<any translate="translation_id"      translate-values='{ username: "pascalprect"}'></any> 

or

<any translate="translation_id"      translate-values="{ username: somescopeobject.username }"></any> 

or

<any translate="translation_id"      translate-values="{{translationdata}}"></any> 

post compiling

starting version 2, translation can post processed in context of current scope (using $compile). means directive used in translation value work expected.

this behavior can enabled per directive:

<any translate="translation_id" translate-compile></any> 

in addition it, can enable feature globally with...

$translateprovider.usepostcompiling(true); 

... , can disable feature again per directive:

<any translate="translation_id" translate-compile="false"></any> 

Comments

  1. Thanks for sharing useful information, Check it once for your bright future Angularjs Online Training

    ReplyDelete

Post a Comment

Popular posts from this blog

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -