2

According to angular.io , it says calling server on constructor is a bad idea and we should do it on other hookup methods of component lifecycle. Why is it so ? . is it about clean separation of responsibility ? Code:

ngOnInit():void{ this.heroes=this.heroService.getHeroes(); //better } constructor(private heroService:HeroService){ this.heroes=this.heroService.getHeroes(); //this is bad } 
1
  • 3
    According to Angular.io, author said that writing code on ngOnInit is much easier for testing also. Ref: angular.io/docs/ts/latest/tutorial/… Commented Jan 4, 2017 at 3:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.