Mark Mark - 2 months ago 19
Jade Question

Translate a string then pass to ng-click

I have a jade template which contains a list and it calls a method called

change()
when an item is clicked. In the example below, I want the
change()
method to be passed the paramaters "category" and "Jobs" (I'm using Angular Translate and have a translation file with "jobs" mapped to "Jobs"). However, the jade compiler doesn't like that and throws an error sayinf:

Syntax Error: Unexpected token
translate='jobs'


My code is:

ul.dropdown-menu
li(ng-click='ctrl.change("category", translate='jobs')')
a(translate='jobs')



change(dimensionKey, dimensionName) {

console.log('in the change and arguments are ', arguments);

}


How can I translate a string then pass to
ng-click
?

Answer

You can use $filter to translate on javascript directly from your translation string ID. Just call the "translate" filter and pass your translation string parameter. For example:

var translate = this.$filter("translate");
var jobsTranslated= translate('jobs');
Comments