Skip to content

Binding <img> 'src' attribute via "data-i18n-attr={ 'src': 'some.key.foo' }" yields 404 #3

@MichaelZalla

Description

@MichaelZalla

It seems that the data-i18n-attr directive assigns temporary values to attributes until the right localization files are loaded, at which point the actual localized values are used for the attributes. (See line 84 in localization.directives.js below).

I'm trying to use this directive to localize an image src. The problem is that the browser attempts to fetch the image by its src (i.e., the key)—thinking that it's a valid image URI—before the actual value is inserted by this directive.

This causes the browser to make a failed (404) image request to the server.

compile: function ($elem, $attrs) {
angular.forEach($rootScope.$eval($attrs.i18nAttr), function (value, key) {
// temporarily populate attribute
// avoid false positive warning about aria-label
setAttr($attrs, key, value || '...');
});
return function ($scope, $elem, $attrs) {
var updateText = getUpdateText($scope, $elem, $attrs);
$attrs.$observe('i18nAttr', function (newVal) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions