0

I would like to use a filter like a i18n engine, and this filter is working fine. However, if I try to use the i18n filter inside a template HTML (using $routeProvider) I can't do this work.

My Filter:

app.filter('i18n', function() {
    return function (input) {
        return $.i18n._(input);
    }
});

My HTML template:

<div class="fieldConfig first">
                <label id="label_topology" for="topology" class="labelMedio">{{"Topologia" | i18n}}:</label>                    
            </div>

My Controller:

function WanCtrl($scope, $routParams, $i18n) {
    $scope.title = 'Wan';

};

Does I need to put anything more in my controller to work my filter inside the template?

Thanks!

backtrack
  • 7,996
  • 5
  • 52
  • 99
z_inx
  • 345
  • 1
  • 3
  • 11

2 Answers2

0

To use filters anywhere (controllers, directives, services, etc.) and not just in templates, you need to reference the $filter service. In your case, you're referencing $i18n in your controller's parameters which isn't the correct way to go about it.

Instead, pass in $filter, and use the i18n filter like so:

function WanCtrl($scope, $routeParams, $filter) {
    $scope.title = $filter('i18n')('Wan');
}

For more explanation, see this StackOverflow post on the matter.

Community
  • 1
  • 1
Jay
  • 18,959
  • 11
  • 53
  • 72
0

A filter like an i18n engine? This is supported in angular-translate! :)

http://pascalprecht.github.io/angular-translate/

Pascal Precht
  • 8,803
  • 7
  • 41
  • 53