Skip to main content
Typo correction
Source Link
Arulkumar
  • 141
  • 2
  • 11

You can use angular.isUndefined and angular.forEach to fine tune the code:

app.filter('categoryTranslations', function() {
  return function(categories, locale) {
    var translated = [];
    if (!angular.isUndefined(categories)) {
        angular.forEach(categories, function(category) {
            angular.forEach(category.CategoryTranslations, function(translation) {
                if (translation.Language.code == locale) {
                    category.defaultTranslation = translation;
                    translated.push(category);
                    break;
                }
            });
        });
    }
    return translated;
  };
});

You can use angular.isUndefined and angular.forEach to fine tune the code:

app.filter('categoryTranslations', function() {
  return function(categories, locale) {
    var translated = [];
    if (!angular.isUndefined(categories) {
        angular.forEach(categories, function(category) {
            angular.forEach(category.CategoryTranslations, function(translation) {
                if (translation.Language.code == locale) {
                    category.defaultTranslation = translation;
                    translated.push(category);
                    break;
                }
            });
        });
    }
    return translated;
  };
});

You can use angular.isUndefined and angular.forEach to fine tune the code:

app.filter('categoryTranslations', function() {
  return function(categories, locale) {
    var translated = [];
    if (!angular.isUndefined(categories)) {
        angular.forEach(categories, function(category) {
            angular.forEach(category.CategoryTranslations, function(translation) {
                if (translation.Language.code == locale) {
                    category.defaultTranslation = translation;
                    translated.push(category);
                    break;
                }
            });
        });
    }
    return translated;
  };
});
Source Link
Arulkumar
  • 141
  • 2
  • 11

You can use angular.isUndefined and angular.forEach to fine tune the code:

app.filter('categoryTranslations', function() {
  return function(categories, locale) {
    var translated = [];
    if (!angular.isUndefined(categories) {
        angular.forEach(categories, function(category) {
            angular.forEach(category.CategoryTranslations, function(translation) {
                if (translation.Language.code == locale) {
                    category.defaultTranslation = translation;
                    translated.push(category);
                    break;
                }
            });
        });
    }
    return translated;
  };
});