javascript - Ionic - JavaScript:访问函数内的属性
问题描述
这可能是一个愚蠢的问题,但我是初学者,所以请帮助我
我想访问一个公共属性并在setTimeout函数中更改它的值,下面是我的代码。
export class AppComponent implements OnInit {
public selectedIndex = 0;
public appPages = [
{
title: 'Trash',
url: '/folder/Trash',
icon: 'trash'
},
{
title: 'Spam',
url: '/folder/Spam',
icon: 'warning'
}
];
public showSplash = true;
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
) {
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
setTimeout(function() {
//showSplash = false ;
console.log('set timeout worked');
}, 300);
});
}
console.log 在setTimeout内工作我需要更改该块中的showSplash值,请帮助我该怎么做
解决方案
我认为是角度和打字稿代码。您可以使用箭头功能。
https://developer.mozilla.org/tr/docs/Web/JavaScript/Reference/Functions/Arrow_functions
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
setTimeout(() => {
this.showSplash = false;
console.log('set timeout worked');
}, 300);
});
}
推荐阅读
- python - 如何在二维列表中搜索单词并创建包含行号、列号和方向的元组?
- windows - 如何在 Windows 中禁用软件 SMI(系统管理中断)
- javascript - 导航栏滚动上的徽标克隆
- oracle - oracle 程序创建并运行 oracle-00900 错误
- java - 如何对 Arraylist 进行排序,以便特定项目排在首位
- r - 四分之一圆 ggplot-s 不存在点
- php - 如果第一个配置失败,则从其他配置发送邮件 laravel
- javascript - 进度条超过 100
- python-3.x - 如何将 S3 存储桶中的选定文件转换为雪花阶段,以便使用 python 和 boto3 将数据加载到雪花中
- java - 将字节数组子集转换为 Java 中的基元