Arter Arter - 20 days ago 8
AngularJS Question

angular-ui-notification and translate message

in my app i use angular-translate for translate my app. Now i start using angular-ui-notification, and I'm stuck. Angular translate does not work when trying to translate messages from the angular-ui-notification.
Angular-translate use this syntax for translate in view

{{ badRequestServerError | translate}}


And here is in my controller for notification

if (response.status == 400) {
Notification.error({message: '{{ badRequestServerError | translate}}', positionY: 'bottom', positionX: 'right'});
};


But this not working. When open i browser i allways get this


{{ badRequestServerError | translate}}


in view I try to use without quotation marks, but still nothing.
On github angular-ui-notification I can not find anything where is explained.

Answer

If $scope.badRequestServerError value is the the translation key, you can inject $filter into your controller and then:

Notification.error({message: $filter('translate')($scope.badRequestServerError), positionY: 'bottom', positionX: 'right'});

Or if you're using the status code of the server response and badRequestServerError is already the translation key, you can just set it this way:

Notification.error({message: $filter('translate')('badRequestServerError'), positionY: 'bottom', positionX: 'right'});