David David - 8 months ago 50
Javascript Question

ngIf=false with ngContent still loads template bindings

Defining a simple component as follows:

selector: 'loader',
template: `<div *ngIf='false'>
export class Loader {}

When using it like this:


I still get template binding errors if model is undefined in the parent, as it tries to resolve the bindings even with the
. Why is this the case?


Because inner content of loader component which is going to projected inside ngContent element, is get compiled once with the current component context (this), even if component template isn't injected to DOM.

It works the same way as ng-transclude work in Angular 1.X

You should use Elvis Operator here to avoid such issue