Skip to main content
Commonmark migration
Source Link

I found the answer and I tried to translate it to english: This question still arised, even in technical interviews. In fact, there is a big resemblance between the two, but also there are some differences.

  • The constructor is part of ECMAScript. On the other hand ngOnInit() is a notion of angular.

  • We can call the constructors in all classes even if we do not use Angular

  • LifeCycle: The constructor is called before ngOnInt ()

  • In the constructor we can not call HTML elements. However, in ngOnInit () we can.

  • Generally, calls of services in the ngOnInit () and not in the constructor

    Source: http://www.angular-tuto.com/Angular/Component#Diff

Source: http://www.angular-tuto.com/Angular/Component#Diff

I found the answer and I tried to translate it to english: This question still arised, even in technical interviews. In fact, there is a big resemblance between the two, but also there are some differences.

  • The constructor is part of ECMAScript. On the other hand ngOnInit() is a notion of angular.

  • We can call the constructors in all classes even if we do not use Angular

  • LifeCycle: The constructor is called before ngOnInt ()

  • In the constructor we can not call HTML elements. However, in ngOnInit () we can.

  • Generally, calls of services in the ngOnInit () and not in the constructor

Source: http://www.angular-tuto.com/Angular/Component#Diff

I found the answer and I tried to translate it to english: This question still arised, even in technical interviews. In fact, there is a big resemblance between the two, but also there are some differences.

  • The constructor is part of ECMAScript. On the other hand ngOnInit() is a notion of angular.

  • We can call the constructors in all classes even if we do not use Angular

  • LifeCycle: The constructor is called before ngOnInt ()

  • In the constructor we can not call HTML elements. However, in ngOnInit () we can.

  • Generally, calls of services in the ngOnInit () and not in the constructor

    Source: http://www.angular-tuto.com/Angular/Component#Diff

Source Link

I found the answer and I tried to translate it to english: This question still arised, even in technical interviews. In fact, there is a big resemblance between the two, but also there are some differences.

  • The constructor is part of ECMAScript. On the other hand ngOnInit() is a notion of angular.

  • We can call the constructors in all classes even if we do not use Angular

  • LifeCycle: The constructor is called before ngOnInt ()

  • In the constructor we can not call HTML elements. However, in ngOnInit () we can.

  • Generally, calls of services in the ngOnInit () and not in the constructor

Source: http://www.angular-tuto.com/Angular/Component#Diff