I am aware some of the facts where ngOnInit()
and constructor differ. also I have come across many examples where services are defined at ngOnInit()
method rather in a constructor and vice-versa.
But using services at constructor level is not prohibited by Angular. If such is the case what benefit it drives in doing so when compared to defining services at ngOInit()
?
Example:
export class App implements OnInit{
constructor(private userService: UserService){
userService.getDetails();
}
ngOnInit(){
userService.getDetails();
}