Angular component field initialization
In my previous post, I talked about Class field initialization in typescript. How about field initialization of angular component, is it different? Angular component is defined an typescript class. It should follow same logics. However, Angular component has life cycle. The ngOnInit is special method that angular will run angular first displays the data-bound properties and sets the directive or component's input properties. So if your initialization code depends on these data-bound proprties and input properties, you can not run them in constructor. So the following code doesn't work
Please your library user with typescript generic
In typescript, generic is a tool that api/library author to please its consumer. What does this means.
Class field initialization in typescript
In typescript class, you can define your field initialization in multiple ways. Here is one typical way to do that.
Minimize the price (not the benefit) of type in Typescript