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 translate-value-* weren't be available on init
Browse files Browse the repository at this point in the history
  • Loading branch information
knalli committed Apr 26, 2015
1 parent d298eb2 commit 98e8279
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/directive/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,21 @@ function translateDirective($translate, $q, $interpolate, $compile, $parse, $roo
scope.postText = '';
var translationIds = {};

// initial setup
if (iAttr.translateValues) {
angular.extend(scope.interpolateParams, $parse(iAttr.translateValues)(scope.$parent));
}
var initInterpolationParams = function (interpolateParams, iAttr, tAttr) {
// initial setup
if (iAttr.translateValues) {
angular.extend(interpolateParams, $parse(iAttr.translateValues)(scope.$parent));
}
// initially fetch all attributes if existing and fill the params
if (translateValueExist) {
for (var attr in tAttr) {
if (Object.prototype.hasOwnProperty.call(iAttr, attr) && attr.substr(0, 14) === 'translateValue' && attr !== 'translateValues') {
var attributeName = angular.lowercase(attr.substr(14, 1)) + attr.substr(15);
interpolateParams[attributeName] = tAttr[attr];
}
}
}
};

// Ensures any change of the attribute "translate" containing the id will
// be re-stored to the scope's "translationId".
Expand All @@ -144,16 +155,6 @@ function translateDirective($translate, $q, $interpolate, $compile, $parse, $roo
}

if (angular.equals(translationId , '') || !angular.isDefined(translationId)) {
// initially fetch all attributes if existing and fill the params
if (translateValueExist) {
for (var attr in tAttr) {
if (Object.prototype.hasOwnProperty.call(iAttr, attr) && attr.substr(0, 14) === 'translateValue' && attr !== 'translateValues') {
var attributeName = angular.lowercase(attr.substr(14, 1)) + attr.substr(15);
scope.interpolateParams[attributeName] = tAttr[attr];
}
}
}

// Resolve translation id by inner html if required
var interpolateMatches = trim.apply(iElement.text()).match(interpolateRegExp);
// Interpolate translation id if required
Expand Down Expand Up @@ -184,6 +185,9 @@ function translateDirective($translate, $q, $interpolate, $compile, $parse, $roo
});
};

// initial setup with values
initInterpolationParams(scope.interpolateParams, iAttr, tAttr);

var firstAttributeChangedEvent = true;
iAttr.$observe('translate', function (translationId) {
if (typeof translationId === 'undefined') {
Expand Down

0 comments on commit 98e8279

Please sign in to comment.