diff --git a/src/directive/translate.js b/src/directive/translate.js index fa23f1471..8031eff6e 100644 --- a/src/directive/translate.js +++ b/src/directive/translate.js @@ -157,16 +157,21 @@ angular.module('pascalprecht.translate') }; } else { return function () { - scope.$watch('interpolateParams', function (value) { - if (scope.translationId && value) { - $translate(scope.translationId, value, translateInterpolation) + + var updateTranslations = function () { + if (scope.translationId && scope.interpolateParams) { + $translate(scope.translationId, scope.interpolateParams, translateInterpolation) .then(function (translation) { applyElementContent(translation, scope); }, function (translationId) { applyElementContent(translationId, scope); }); - } - }, true); + } + }; + + // watch both interpolateParams and translationId, because watchers are triggered non-deterministic + scope.$watch('interpolateParams', updateTranslations, true); + scope.$watch('translationId', updateTranslations); }; } }()); diff --git a/test/unit/directive/translate.spec.js b/test/unit/directive/translate.spec.js index 7b7c330c8..066d7f952 100644 --- a/test/unit/directive/translate.spec.js +++ b/test/unit/directive/translate.spec.js @@ -329,6 +329,21 @@ describe('pascalprecht.translate', function () { $rootScope.$digest(); expect(element.text()).toEqual('hello my name is Glenn Jorde.'); }); + + // addresses [issue #433](https://github.com/angular-translate/angular-translate/issues/433) + it('should interpolate variables inside ng-if directives', function () { + var markup = '

'; + element = $compile(markup)($rootScope); + $rootScope.$digest(); + expect(element.next().text()).toEqual('hello my name is Pascal'); + }); + + iit('should interpolate variables inside ng-repeat directives', function () { + var markup = '

'; + element = $compile(markup)($rootScope); + $rootScope.$digest(); + expect(element.children().text()).toEqual('hello my name is Pascal'); + }); }); describe('translate sanitization', function () {