I'm trying to use the following code to subscribe, but it doesn't 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'm using Ionic 2 with TypeScript, Angular 2. As platform.pause
is an EventEmitter provided by Ionic 2, I suppose it should be able to be subscribed. However, when I put the application to the background, console.log('pause')
is not fired.
Should I add Platform
to providers or something like that? Plus, this.platform is not null
. this.platform.ready().then(()=>{console.log('ready')})
works perfectly.
I think you missed 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');
});
});
}
The above code worked for me. Hope it helps you as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With