One of the things I like about typescript is its type safety and I use it consistently.
Typescript does not support multiple inheritance, so how can I extend an Angular 2 component class by OnInit
and OnChanges
at the same time?
I know that it works without declaring the inheritance but I like my code without squiggly lines.
OnInit
and OnChanges
are not classes but interfaces, so your components don't inherit but implement those interfaces.
As a class can implements as many interfaces as it needs, there is no problem implementing both OnInit
and OnChanges
interfaces on the same component.
For example:
class FooComponent implements OnInit, OnChanges {
}
For more information, have a look at Angular Lifecycle Hooks guide.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With