Lifecycle hooks

Most methods you will create in classes must be called somewhere by you, which is the expected pattern in programming. This is not the case in what Angular defines as lifecycle hooks. These hooks are methods that you create for Angular to call them internally, depending on the current state of a component/directive. They are created in a component's or directive's class.

The following hooks are available in an Angular component:

  • ngOnChanges: Remember how properties are bound to components. These properties are reactive, meaning that, when they change, the view is updated as well. This lifecycle method is called when any property, bound to a view, is changed. Therefore, you can manipulate what happens before the changes are ...

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.