What's wrong with that code:
@Directive({
selector: '[appDir]'
})
export class DirDirective {
constructor(
private vcr: ViewContainerRef,
private compFactoryResolver: ComponentFactoryResolver
) {}
ngAfterViewInit() {
const compAFactory = this.compFactoryResolver.resolveComponentFactory(
CompAComponent
);
const compBFactory = this.compFactoryResolver.resolveComponentFactory(
CompBComponent
);
const compARef = this.vcr.createComponent(compAFactory);
this.vcr.createComponent(compBFactory, 0, undefined, [
[compARef.location.nativeElement]
]);
}
}
Only fails when IVY is enable
https://stackblitz.com/edit/angular-h3wqc4?file=src%2Fapp%2Fdir.directive.ts