Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Constractor in Ionic

$
0
0

@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

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>