1.

What are the lifecycle hooks available?

Answer»

There are many lifecycle hooks available in AngularJS and they are:

  • NGONINIT(): This is a CALLBACK method that gets invoked as soon as the change detector detects any scope model changes for the first time and before any view has been checked. This is invoked once only when the directive is instantiated.
  • ngOnChanges(): This callback function is triggered whenever AngularJS detects changes in the scope model and we can define the actions that need to follow up with that change in the PROPERTY. It is called before ngOnInit() while instantiating the directive and is called every time the scope model changes.
  • ngDoCheck(): This callback method does the task of change-detection and is invoked only after the default change-detector is run.
  • ngAfterContentInit(): This is invoked once and that too as soon as AngularJS completes the initialization of all content of the DIRECTIVES.
  • ngAfterContentChecked(): This callback method is invoked as soon as the default change-detector completes checking the content of the directives.
  • ngOnDestroy(): This is USED to clean up any component just before the directives or its properties are destroyed. They are useful for avoiding memory leaks and unsubscribe any unnecessary observables.
  • ngAfterViewChecked(): This is immediately invoked once the default change-detector completes one cycle of change-check.


Discussion

No Comment Found