简体   繁体   中英

Property 'platform' is declared but never used

Why I got this warning by tslint?

Package name: io.ionic.starter
[18:37:16]  tslint: s:/IonicProject/VerificheNawi/src/pages/home/home.ts, line: 14
        Property 'platform' is declared but never used.

  L14:    constructor(public navCtrl: NavController, private platform: Platform, public splash: SplashScreen) {
  L15:      platform.ready().then(()  => {

As you can see, L15 use platform... I wonder if there is something I didn't yet understood about injection.

The problem is the line number 14. So try with this:

constructor(platform: Platform, public navCtrl: NavController, public splash: SplashScreen) {

by omitting the private keyword for the platform in the constructor, we're telling Typescript not to create a property for it, in this component.

Why? Since you're using the platform like this: platform.ready... you're not using the property from the component, but the parameter from the constructor .

So as I see it, you could fix that in two ways:

  1. Remove the private keyword next to the platform, in the constructor , in order to not create a property in the component, and just use the platform parameter.
  2. Change platform.ready().then(...) by this.platform.ready().then(..) to use the property from the component (by using the this keyword).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM