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

Commit

Permalink
fix(directive): Fix behavior of translate-cloak timing
Browse files Browse the repository at this point in the history
Instead of removing the cloak only when the instance of the directive has been created before the first translations have been loaded, this ensures the cloak will be removed at any time using the new `$translate.onReady()`.

Fixes #929
Fixes #1175
  • Loading branch information
knalli committed Sep 17, 2015
1 parent 9a4bd0d commit a6adf47
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/directive/translate-cloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ angular.module('pascalprecht.translate')
*/
.directive('translateCloak', translateCloakDirective);

function translateCloakDirective($rootScope, $translate) {
function translateCloakDirective($translate) {

'use strict';

Expand All @@ -33,11 +33,9 @@ function translateCloakDirective($rootScope, $translate) {
},
removeCloak = function () {
tElement.removeClass($translate.cloakClassName());
},
removeListener = $rootScope.$on('$translateChangeEnd', function () {
};
$translate.onReady(function () {
removeCloak();
removeListener();
removeListener = null;
});
applyCloak();

Expand Down
4 changes: 2 additions & 2 deletions test/unit/directive/translate-cloak.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ describe('pascalprecht.translate', function () {
});

describe('an element added after the first translation', function () {
it('should still have translate-cloak', function () {
it('should have not translate-cloak', function () {
element = $compile('<div translate-cloak></div>')($rootScope);
$rootScope.$digest();
expect(element.hasClass('translate-cloak')).toBe(false);
$timeout(function () {
var element2 = $compile('<div translate-cloak></div>')($rootScope);
$rootScope.$digest();
expect(element2.hasClass('translate-cloak')).toBe(true);
expect(element2.hasClass('translate-cloak')).toBe(false);
}, 100);
$timeout.flush();
});
Expand Down

0 comments on commit a6adf47

Please sign in to comment.