ionic-framework – 如何订阅Ionic 2 platform.pause EventEmitt
发布时间:2020-12-17 07:25:12 所属栏目:安全 来源:网络整理
导读:我正在尝试使用以下代码进行订阅,但它不起作用. import { Platform } from 'ionic-angular';@Page({ templateUrl: 'build/pages/test.html',}) export class Test{ constructor(private platform: Platform) { this.platform.pause.subscribe(() = { console
我正在尝试使用以下代码进行订阅,但它不起作用.
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') }); } } 我正在使用Ionic 2和TypeScript,Angular 2.作为platform.pause是Ionic 2提供的EventEmitter,我想它应该可以订阅.但是,当我将应用程序放到后台时,不会触发console.log(‘pause’). 我应该向提供商或类似的东西添加平台吗?另外,this.platform不为null. this.platform.ready().then(()=> {console.log(‘ready’)})完美无缺.
我想你错过了platform.ready(),如下所示
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'); }); }); } 上面的代码对我有用.希望它也能帮到你. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |