Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
fix(directive): Make translate-value-* work inside ng-if and ng-repeat
Browse files Browse the repository at this point in the history
Closes Issue #433
  • Loading branch information
damienklinnert authored and 0x-r4bbit committed Apr 2, 2014
1 parent 877b4fe commit e07eea7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/directive/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
}());
Expand Down
15 changes: 15 additions & 0 deletions test/unit/directive/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<div ng-if="true"><p translate="FOO" translate-value-name="{{name}}"></p></div>';
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 () {

This comment has been minimized.

Copy link
@allan-simon

allan-simon Sep 2, 2014

iit ? with two i ?

This comment has been minimized.

Copy link
@tspaeth

tspaeth Sep 2, 2014

Member

iit tells Jasmine to run selected tests. But you're right in this case as it normally disables running the other tests.

This comment has been minimized.

Copy link
@knalli

knalli Sep 2, 2014

Member

fixed in 72070f7

var markup = '<div><div ng-repeat="i in [1]"><p translate="FOO" translate-value-name="{{name}}"></p></div></div>';
element = $compile(markup)($rootScope);
$rootScope.$digest();
expect(element.children().text()).toEqual('hello my name is Pascal');
});
});

describe('translate sanitization', function () {
Expand Down

0 comments on commit e07eea7

Please sign in to comment.