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(() => {
如您所见,L15使用平台...我想知道关于注射我是否还不了解某些内容。
问题是第14行。因此,请尝试以下操作:
constructor(platform: Platform, public navCtrl: NavController, public splash: SplashScreen) {
通过private
在构造函数中省略平台的关键字,我们告诉Typescript在此组件中不要为其创建属性。
为什么?由于您使用的是这样的平台:platform.ready...
您不是在使用组件的属性,而是在构造函数的参数。
因此,如我所见,您可以通过两种方式解决此问题:
private
平台旁边的关键字,以constructor
使用该platform
参数。platform.ready().then(...)
通过this.platform.ready().then(..)
(通过使用以使用从该组件的属性this
的关键字)。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句