ionic 4 电容器不适用于 ionic/angular 我需要添加事件
ionic 4 capacitor not working with ionic/angular i need to add Event
在 ionic 4 中,电容器 ionic/angular 不工作。
我需要添加一个事件并订阅它来跟踪登录和注销时间
有谁知道更详细的电容器插件文档,其实现示例类似于 ionic 文档。
我检查过the capacitor homepage但是文档很少而且只列出了几个插件?
angular 上的事件已被取消,因此您需要创建自己的服务来实现该事件并执行此操作,请执行以下操作:
创建事件服务。
在 EventService.ts:
export class EventService {
private dataObserved = new BehaviorSubject<any>('');
currentEvent = this.dataObserved.asObservable();
constructo(){}
publish(param):void {
this.dataObserved.next(param);
}
}
用于发布示例页面 1 中的事件:
constructor(public eventService:EventService){}
updatePost(){
this.eventService.publish('post:updated');
// or
this.eventService.publish({name: 'postupdate', value: 'value you need to pass'});
}
在第 2 页中:
constructor(public eventService:EventService){
this.eventService.currentEvent.subscribe(data=>{
// here you can get the data or do whatever you want or data.name or data.value
});
}
在 ionic 4 中,电容器 ionic/angular 不工作。 我需要添加一个事件并订阅它来跟踪登录和注销时间
有谁知道更详细的电容器插件文档,其实现示例类似于 ionic 文档。
我检查过the capacitor homepage但是文档很少而且只列出了几个插件?
angular 上的事件已被取消,因此您需要创建自己的服务来实现该事件并执行此操作,请执行以下操作:
创建事件服务。 在 EventService.ts:
export class EventService {
private dataObserved = new BehaviorSubject<any>('');
currentEvent = this.dataObserved.asObservable();
constructo(){}
publish(param):void {
this.dataObserved.next(param);
}
}
用于发布示例页面 1 中的事件:
constructor(public eventService:EventService){}
updatePost(){
this.eventService.publish('post:updated');
// or
this.eventService.publish({name: 'postupdate', value: 'value you need to pass'});
}
在第 2 页中:
constructor(public eventService:EventService){
this.eventService.currentEvent.subscribe(data=>{
// here you can get the data or do whatever you want or data.name or data.value
});
}