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 … and lot of them.
- Constructor : As with the ES6, you can use the super() constructor
- LifeCycle : You can also herit of parent lifeCycle.
But, there is no inheritance betwen templates. You should manage it separately.
Lets see an example of use :
And the plnkr :
For this moment, we can instantiate an abstract component. I have opened an issue on github. Wait and see ….
Les derniers articles par William Koza (tout voir)
- Do an upload with Angular and ngx-upload - 6 mars 2019
- How can we have multiple instances of HttpClient with Angular ? - 18 septembre 2018
- Retrieve your ngfactory, .metadata.json and .ngsummary.json with Angular 5 - 8 avril 2018