angular-gettext icon indicating copy to clipboard operation
angular-gettext copied to clipboard

element.parent not a function for empty item

Open asmund1 opened this issue 9 years ago • 1 comments

If I have the translate keyword on an empty item (in this case a div)

    <div translate>

    </div>

I get the following error:

TypeError: element.parent is not a function
    at queueAnimation (http://localhost:8100/lib/ionic/js/ionic.bundle.js:43785:26)
    at Object.push (http://localhost:8100/lib/ionic/js/ionic.bundle.js:43737:16)
    at Object.enter (http://localhost:8100/lib/ionic/js/ionic.bundle.js:18494:31)
    at update (http://localhost:8100/lib/angular-gettext/dist/angular-gettext.js:223:34)
    at post (http://localhost:8100/lib/angular-gettext/dist/angular-gettext.js:233:21)
    at invokeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21963:9)
    at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21463:11)
    at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20854:13)
    at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20858:13)
    at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21458:24) <div translate="">

Seems like the contents() function on angular-gettext.js:221

var newContents = newWrapper.contents();

strips away the span of the element created on angular-gettext.js:219 if the span is empty (the translation is empty).

One (not very elegant) workaround is to add a space when creating the span element, which is then treated as not empty:

var newWrapper = angular.element('<span> ' + translated + '</span>');

asmund1 avatar Jan 13 '16 13:01 asmund1

This seems to be caused by https://github.com/angular/angular.js/issues/11703 But it is still broken sometimes

andrey-skl avatar Apr 26 '16 12:04 andrey-skl