Sikander Nawaz
Sikander Nawaz

Reputation: 131

Ionic - JavaScript : Accessing properties inside a function

it might be a silly question but i am a beginner so please help me on this

i want to access a public property and change its value inside setTimeout function, Below is my code .

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 works inside setTimeout i need to change showSplash value in that block, Please help how can i do that

Upvotes: 0

Views: 105

Answers (1)

Muhammet Can TONBUL
Muhammet Can TONBUL

Reputation: 3538

I think is angular and typescript code. You can use arrow function.

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);
  });
}

Upvotes: 1

Related Questions