Angular 2, decorators and class inheritance

What about such a support in Angular 2?

What do decorators actually do in Angular 2?

Decorators in Angular 2
  • annotations. This corresponds to metadata set by decorators at the class level. It’s an array since you can apply several decorators at this level. For example, @Component and @Routes.
  • design:paramtypes. This corresponds to the types of constructor parameters. It only applies for TypeScript since with ES6, such parameters aren’t supported. With this language, you need to supply a static getter for the parameters property.
  • propMetadata. This corresponds to metadata set by decorators at the class property level. It’s an object and each entry name is the property name. Each entry contains an array since it’s also possible to define several decorators on a property.
  • parameters. This corresponds to metadata set by decorators at the constructor parameter level. It’s an array of arrays since it’s always possible to define several decorators on a parameter.

Support of base components

Getting metadata from the parent class
Metadata building from the parent ones
Using the custom decorator

Leveraging parent classes for dependency injection

Metadata building from the parent ones

Conclusion

References

--

--

--

Freelance developer (github: templth) — Angular 2, React, Node addict and co-author of the “Angular 2 components” book at Packt Publishing.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thierry Templier

Thierry Templier

Freelance developer (github: templth) — Angular 2, React, Node addict and co-author of the “Angular 2 components” book at Packt Publishing.

More from Medium

Angular, Move rows up or down on the base of the selection

Azure AD with Angular and Express.js

Three ways to set environment variables in Angular

yield: the C# iterator