[英]Property 'platform' is declared but never used
Why I got this warning by tslint? 为什么我通过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. 正如你所看到的,L15使用平台......我想知道是否有一些我还没有理解注射的东西。
The problem is the line number 14. So try with this: 问题是第14行。所以试试这个:
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. 通过在构造函数中省略平台的private
关键字,我们告诉Typescript 不要在此组件中为它创建属性 。
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 . 因为你正在使用这样的平台: platform.ready...
你没有使用组件中的属性,而是使用构造函数中的参数 。
So as I see it, you could fix that in two ways: 所以我看到它,你可以通过两种方式解决这个问题:
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. 在constructor
删除平台旁边的private
关键字,以便不在组件中创建属性,只需使用platform
参数。 platform.ready().then(...)
by this.platform.ready().then(..)
to use the property from the component (by using the this
keyword). 通过this.platform.ready().then(..)
更改platform.ready().then(...)
以使用组件中的属性(通过使用this
关键字)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.