@EvgenyBo wrote:
A newbiw question about the constractor in Ionic V2
Why do we need to inject any services that we
want to use inside of the class into the constructor like this?constructor(platform: Platform, nav: NavController) {
}
Why not simply declaring the platform: Platform and nav: NavController as Class member variables wont work? Aren't they instantiated too when class is created?
Just as normal variables:
rootPage:any = HomePage;
someVariable: String= "hey!";I ask because I didn't see the need of a class declared in Ionic to be declared with the new keyword like:
HomePage homepage = new HomePage (platform, nav);
I thought the main use of constractor is to instantiate the class with variables we pass when
we create new instance of the class.
Posts: 1
Participants: 1