Custom code can be invoked from various places of your component’s TypeScript code:
- in the constructor()
- in ngAfterContentInit() of AfterContentInit
- in ngAfterViewInit() of AfterViewInit
Logging to the console shows that code is executed in the following order
- asynchronous code invoked in constructor (e.g. by http.get())
(for more details, see Angular’s documentation of Lifecycle Hooks)
Whereas in ASP.Net MVC we have a strict distinction between Controller and View, and process and data flow are from the controller to the view, and the view cannot (usually does not) reference the controller, this distinction does not apply in Angular2, where we end up in the component after the template has been rendered.