fix(ivy): support ICU expressions inserted in ngTemplateOutlets inside ngFors (#31789)
This commit fixes a bug where ICU expressions inserted into ngTemplateOutlets that are inside ngFor blocks would throw an error. We were assuming in view insertion code that text nodes would always exist by the time a view\`s creation block had executed. This is not true for text nodes created dynamically by ICUs because this happens in the update block (in `i18nApply`). This change ensures such dynamically created nodes are skipped when encountered too early (as they will be attached later by i18n code anyway). PR Close #31789
This commit is contained in:
@ -921,6 +921,38 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
|
||||
expect(fixture.debugElement.nativeElement.innerHTML).not.toContain('A - Type A');
|
||||
expect(fixture.debugElement.nativeElement.innerHTML).toContain('other - Type C');
|
||||
});
|
||||
|
||||
it('should work inside an ngTemplateOutlet inside an ngFor', () => {
|
||||
@Component({
|
||||
selector: 'app',
|
||||
template: `
|
||||
<ng-template #myTemp i18n let-type>{
|
||||
type,
|
||||
select,
|
||||
A {A }
|
||||
B {B }
|
||||
other {other - {{ typeC // i18n(ph="PH WITH SPACES") }}}
|
||||
}
|
||||
</ng-template>
|
||||
|
||||
<div *ngFor="let type of types">
|
||||
<ng-container *ngTemplateOutlet="myTemp; context: {$implicit: type}">
|
||||
</ng-container>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
class AppComponent {
|
||||
types = ['A', 'B', 'C'];
|
||||
}
|
||||
|
||||
TestBed.configureTestingModule({declarations: [AppComponent]});
|
||||
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.debugElement.nativeElement.innerHTML).toContain('A');
|
||||
expect(fixture.debugElement.nativeElement.innerHTML).toContain('B');
|
||||
});
|
||||
});
|
||||
|
||||
describe('should support attributes', () => {
|
||||
|
Reference in New Issue
Block a user