How to subscribe to Ionic 2 platform.pause EventEmitter?

I am trying to use the following code to subscribe, but it does not work.

import { Platform } from 'ionic-angular'; @Page({ templateUrl: 'build/pages/test.html', }) export class Test{ constructor(private platform: Platform) { this.platform.pause.subscribe(() => { console.log('paused') }); } } 

I am using Ionic 2 with TypeScript, Angular 2. Since platform.pause is an EventEmitter provided by Ionic 2, I assume that it should be signed. However, when I put the application in the background, console.log('pause') does not start.

Should I add Platform to providers or something like that? In addition, this platform is not null . this.platform.ready().then(()=>{console.log('ready')}) works fine.

+8
angular ionic-framework ionic2
source share
1 answer

I think you skipped platform.ready () as below

 constructor( private platform: Platform ) { platform.ready().then(() => { this.platform.pause.subscribe(() => { console.log('[INFO] App paused'); }); this.platform.resume.subscribe(() => { console.log('[INFO] App resumed'); }); }); } 

This code worked for me. I hope he helps you too.

+8
source share

All Articles