Use variables like $ scope or $ timeout in the constructor in Ionic

1

I am new to Ionic and I am trying to use the background plugin, I have the following simple and functional my application builder:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { BackgroundMode } from '@ionic-native/background-mode';
import { TabsPage } from '../pages/tabs/tabs';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = TabsPage;


  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private backgroundMode: BackgroundMode) {
    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();

      // Configuracion de background 
      this.backgroundMode.enable();
    });
  }
}

Gem works! Now, I want to add the following line below this.backgroundMode.enable(); :

$timeout(function() {
    this.backgroundMode.moveToBackground();
}, 500);

The problem is that I do not know how to import $timeout , like $scope , which are variables that are automatically passed with controllers, but here I have no idea how to import or declare them. I tried adding them as a constructor parameter, but it did not work.

Thank you very much!

    
asked by Genarito 16.08.2017 в 21:08
source

1 answer

2

You can import

import {TimerWrapper} from '@angular/core/src/facade/async';

And use it:

TimerWrapper.setTimeout(() => {  
 this.backgroundMode.moveToBackground();
}, 3000);

Or as you propose, since it changes the syntax

setTimeout(() => {  
 this.backgroundMode.moveToBackground();
}, 3000);
    
answered by 16.08.2017 / 21:43
source