I am starting in angular2 and I'm curious about this code
export class HeroesComponent implements OnInit {
myHero: Hero = new Hero('Superman', 'Clark Kent');
constructor() {
}
ngOnInit() {
}
}
Right now I have myHero initialized at the top, but I wonder what happens at the top, what should be inside the constructor and what happens inside ngOnInit?
Because, as far as I know, if it is at the top, it runs immediately, like the constructor, and ngOnInit?
So what's the difference, and what's right?
thank
source
share