Angular 4 component lifecycle

Viewed 8752

I am trying to use the component life cycle hooks that are exposed by Angular 4 to process certain information related to the component.
When I tried to search I was able to find the list of life cycle hooks that are exposed by angular 4 (https://angular.io/guide/lifecycle-hooks)
I am more interested in the code snippet that triggers few of these methods. For example in Java following lines of code would trigger the constructor in 'String' class:

String hotelName = new String("Marriott");

What would be the HTML, JavaScript code that would trigger following life cycle methods:

  • constructor
  • ngOnInit
  • ngAfterViewInit
  • ngAfterViewChecked
  • ngOnDestroy

Thanks in advance.

1 Answers

In Angular all lifecycle hooks are triggered as part of change detection by the framework. To learn more about the process read:

For example in Java following lines of code would trigger the constructor in 'String' class:

Constructor is not a lifecycle hook and is triggered when a component is created. It's similar mechanics to the one you showed which includes calling a component constructor with new.

To learn more read:

Related