How to call an asynchronous service before bootstrap ?

Sometimes, we have to fetch datas before our application boostrap is started. It happens when we have to fetch a server configuration before calling an API. Angular offers a poorly documented system : the APP_INITIALIZER provider. APP_INITIALIZER is a multi provider, that is, a provider that accepts several values. But this provider is special…

lire la suite

ng-container or ng-template, that is the question.

When we use a structural directive as *ngIf, we use a sugar such as : <div *ngIf="true">Hello World !</div> Before it will be rendered, it will be "de-sugared" : <ng-template [ngIf]="true"><div>Hello World</div></ng-template>​     But, if you just want to show "Hello World" without to wrap it with another element in the…

lire la suite

How ng-content and selector can help you ?

When you want to add dynamic content in a fixed view template, you should think Transclusion. This mecanism allow you to define a hook for dynamic content by using <ng-content> tag.  For exemple, CardComponent is a component that uses this mechanism :  View the code on Gist. We can see this component as…

lire la suite

Components inheritance

Since Angular 2.3, we can use Components inheritance. The feature improve code reusability and desgin of our applications. This feature covers all of the following : Metadata : You can herit of parent properties or override them. So, we can inherit from @NgModule, @Host, @Self @SkipSelf, @Inject, @Optionnal, @Attribute, @ContentChild, @ContetnChildren, @ViewChild ……

lire la suite