fix(ivy): better support for i18n attributes on <ng-container>s (#33599)
Prior to this commit, i18n runtime logic used `elementAttributeInternal` function (that uses `setAttribute` function under the hood) for all elements where i18n attributes are present. However the `<ng-container>` elements in a template may also have i18n attributes and calling `setAttribute` fails, since they are represented as comment nodes in DOM. This commit ensures that we call `setAttribute` on nodes with TNodeType.Element type (that support that operation) only. PR Close #33599
This commit is contained in:

committed by
Andrew Scott

parent
3419b5002f
commit
204620291e
@ -1268,6 +1268,33 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
expect(comp.attributes['messagetext']).toBe('Bonjour');
|
||||
expect(comp.attributes['ng-reflect-message-text']).toBe('Bonjour');
|
||||
});
|
||||
|
||||
it('should support i18n attributes on <ng-container> elements', () => {
|
||||
loadTranslations({[computeMsgId('Hello', 'meaning')]: 'Bonjour'});
|
||||
|
||||
@Directive({selector: '[mydir]'})
|
||||
class Dir {
|
||||
@Input() mydir: string = '';
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'my-cmp',
|
||||
template: `
|
||||
<ng-container i18n-mydir="meaning|description" mydir="Hello"></ng-container>
|
||||
`,
|
||||
})
|
||||
class Cmp {
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [Cmp, Dir],
|
||||
});
|
||||
const fixture = TestBed.createComponent(Cmp);
|
||||
fixture.detectChanges();
|
||||
|
||||
const dir = fixture.debugElement.childNodes[0].injector.get(Dir);
|
||||
expect(dir.mydir).toEqual('Bonjour');
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with directives and host bindings', () => {
|
||||
|
Reference in New Issue
Block a user