It seems to be similar functions, what are the main differences and purposes of them
//Code
import { OnInit } from '@angular/core';
constructor(){
}
ngOnInit(){
}
It seems to be similar functions, what are the main differences and purposes of them
//Code
import { OnInit } from '@angular/core';
constructor(){
}
ngOnInit(){
}
People have already mentioned life cycle hooks so I won't talk about that. However, Angular docs state that in the constructor you should only do lightweight operations such as simple sync variable assignments.
In ngOnInit you should do more heavy lifting operations such as HTTP requests, etc