angulardecoratorangular-decorator

Why does Angular 2 use decorators?


I just started using Angular 2 and was wondering why some properties like selector and template are put in components decorators and not in components classes.

What's the point of using all these decorators in Angular 2?


Solution

  • Code would need to be executed to use results expressions might emit. Decorators can be easily evaluated statically without executing the TypeScript code (except maybe a simple and limited subset).