InterviewSolution
| 1. |
constructor available? |
|
Answer» Like any other OOP language, for example JAVA, C# etc., a constructor is a special named function WITHIN a class. The constructor is CALLED when the class in instantiated. It is out of Angular’s control when the constructor is INVOKED, which means that it’s not a suitable hook to let you know when Angular has finished initialising the component. By adding the ngOnInit lifecycle hook, Angular fires a method once it has finished setting the component up, and the hook is part of the component’s lifecycle. ngOnInit is purely there to give us a signal that Angular has finished initialising the component and we can hook any code that we want executed in the ngOnInit function. |
|