fix(ivy): move i18n instructions after listener ones (#29173)

Prior to this commit, i18n instructions (i18n, i18nStart) were generated before listener instructions. As a result, event listeners were attached to the wrong element (text node, not the parent element). This change updates the order of instructions and puts i18n ones after listeners, to make sure listeners are attached to the right elements.

PR Close #29173
This commit is contained in:
Andrew Kushnir
2019-03-07 14:24:54 -08:00
committed by Kara Erickson
parent aa6db0d191
commit fd5cd100a3
3 changed files with 48 additions and 6 deletions

View File

@ -28,6 +28,9 @@ class MyComp {
age = 20;
count = 2;
otherLabel = 'other label';
clicks = 0;
onClick() { this.clicks++; }
}
const TRANSLATIONS: any = {
@ -254,6 +257,23 @@ onlyInIvy('Ivy i18n logic').describe('i18n', function() {
const element = fixture.nativeElement.firstChild;
expect(element).toHaveText('Bonjour John');
});
it('should work correctly with event listeners', () => {
const content = 'Hello {{ name }}';
const template = `
<div i18n (click)="onClick()">${content}</div>
`;
const fixture = getFixtureWithOverrides({template});
const element = fixture.nativeElement.firstChild;
const instance = fixture.componentInstance;
expect(element).toHaveText('Bonjour John');
expect(instance.clicks).toBe(0);
element.click();
expect(instance.clicks).toBe(1);
});
});
describe('ng-container and ng-template support', () => {