Directives such as ngIf
, ngClass
, ngStyle
don't work in lazy loaded component (introduced in Angular 9).
core.js:12626 Can't bind to 'xxx' since it isn't a known property of 'xxx'.
The only binding I managed to get it working is something like: [style.color]="color"
.
Lazy loading the webpack js bundle works fine as long as there is no binding or there is just simple binding as [style.color]="color"
.
The Lazy loaded component is not declared in NgModule and it is loaded as such
async lazy1() {
this.viewContainerRef.clear();
const { LazyComponent } = await import("./lazy.component");
this.viewContainerRef.createComponent(
this.cfr.resolveComponentFactory(LazyComponent)
);
}
Full example (can't be run in stackblitz for some reason): https://stackblitz.com/edit/angular-zyp3wm
This can e reproduced in a step by step fashion by following the article below
https://johnpapa.net/angular-9-lazy-loading-components/
You just need to add a ngIf
somewhere in a one of the lazy component to get the problem I am experiencing.