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

Commit

Permalink
fix(directive): ensure internal watcher will be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
knalli committed Dec 11, 2014
1 parent 5e4533a commit e69f4a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/directive/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ angular.module('pascalprecht.translate')
// be re-stored to the scope's "translationId".
// If the attribute has no content, the element's text value (white spaces trimmed off) will be used.
var observeElementTranslation = function (translationId) {

// Remove any old watcher
if (angular.isFunction(observeElementTranslation._unwatchOld)) {
observeElementTranslation._unwatchOld();
observeElementTranslation._unwatchOld = undefined;
}

if (angular.equals(translationId , '') || !angular.isDefined(translationId)) {
// Resolve translation id by inner html if required
var interpolateMatches = iElement.text().match(interpolateRegExp);
Expand All @@ -124,7 +131,7 @@ angular.module('pascalprecht.translate')
translationIds.translate = $interpolate(interpolateMatches[2])(scope.$parent);
var watcherMatches = iElement.text().match(watcherRegExp);
if (angular.isArray(watcherMatches) && watcherMatches[2] && watcherMatches[2].length) {
scope.$watch(watcherMatches[2], function (newValue) {
observeElementTranslation._unwatchOld = scope.$watch(watcherMatches[2], function (newValue) {
translationIds.translate = newValue;
updateTranslations();
});
Expand Down

0 comments on commit e69f4a1

Please sign in to comment.