I have a the following situation (a translation filter in a service, used in the HTML file)
// serviceFile
angular.module('myModule')
.service('translation')
.filter('translate', function(translation) {
// translate stuff
return 'translatedString';
});
// controllerFile
angular.module('myModule')
.controller('StringsController', function(blabla, translation) {
$scope.mySort = function() {
return "some magic should happen here";
};
});
// htmlFile
<tr ng-repeat="string in strings">
<td>
{{ string | translate: 'name' }}
</td>
</tr>
(The above code works, but perhaps some vital parts were omitted due to my lack of experience)
My issue is that I am requested to sort based on the translated values (something like string in strings | orderBy: mySearch
) and I can't find how to call the filter programatically from the StringsController.mySearch
P.S. the filter is not returned from the service (don't know if this is relevant)
You can see guide for filters
So in your case depends from defininition .filter('translate',
you can use it like
.controller('StringsController', function(blabla, $filter) {
//simple transtale
var translatedString = $filter('translate')(stringForTranslate);
//ordering
var ordered = $filter('orderBy')(arrayForOrdering,function(el){ return $filter('translate')(el); })
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With