How does an angular component class get instantiated?

1.5k Views Asked by At

I'm new to Angular and I see that we use classes for components. But I don't see anywhere instantiating classes and making object instances from them by using the new keyword for example. We just define a class and use it. Some classes does not even have a constructor, like the app.component.ts, only title property inside. How come? In one article I was reading it says

Constructor is invoked when Angular creates a component or directive by calling new on the class.

So where is new being called? Is it all happening behind the scenes? So angular instantiate classes and make objects out of them on the compile time, when compiling from TS to JS? If so, where can I find JS source code for this to see real example of it?

This is really confusing for me and I really want to understand how Angular 2+ works under the hood. Some links to more articles about it would be nice too, to see all the javascript logic and magic for this framework.

Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER
class A {
  title = 'foo';
}

It is a Field declarations and it's the same as

class A {
  constructor(){
    this.title = 'foo';
  }
}

New instance created when angular runtime decide to show component.