Decorating classes

Another commonly decorated member is the class. In fact, in Angular, almost all classes (components, services, modules, filters, and directives) are decorated. This is why it is important to understand the importance of the existence of decorators.

Decorators can be used to extend the features of a class, as shown in the following example:

// decorator functionfunction config(target) {  target.options = {    id: '#main',    show: true  }}// class@configclass App {}// options addedconsole.log(App.options) // {id: '#main', show: true}

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.