我有一个带有3个选项卡的简单项目.当用户点击第一个标签上的项目上的按钮时,我需要该项目移动到第二个标签,反之亦然.(当发生这种情况时,我还需要通知服务器).有没有办法让我将项目对象传递给About-Page选项卡中的数组,反之亦然?
home.html的
<ion-header>
<ion-toolbar>
<ion-title>Home</ion-title>
<ion-buttons end>
<button ion-button icon-only color="royal" (click)="updateData()">
<ion-icon name="refresh"></ion-icon>
</button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item-sliding *ngFor="let item of items">
<ion-item>
<ion-icon name="alert" *ngIf="!item.taken" item-left></ion-icon>
<ion-icon name="checkmark-circle-outline" *ngIf="item.taken" item-left></ion-icon>
<h2><b>{{item.title}}</b></h2>
<h3>{{item.name}} | {{item.number}}</h3>
<h3 style="white-space: normal;"><b>Details:</b> {{item.text}}</h3>
</ion-item>
<ion-item-options side="left">
<button ion-button color="primary" (click)="smsPressed(item)">
<ion-icon name="text"></ion-icon>
Text
</button>
<button ion-button color="secondary" (click)="phonePressed(item)">
<ion-icon name="call"></ion-icon>
Call
</button>
</ion-item-options>
<ion-item-options side="right">
<button ion-button color="primary" *ngIf="item.taken" (click)="responderPressed(item)">
<ion-icon name="person"></ion-icon>
Responder
</button>
<button ion-button color="primary" *ngIf="!item.taken" (click)="takecallPressed(item)">
<ion-icon name="navigate"></ion-icon> …Run Code Online (Sandbox Code Playgroud) 我知道 Ionic 事件将在下一个版本中被弃用。目前,我使用事件从子组件执行父页面中的函数。下面是一个例子:
在我的主页中,它订阅了要刷新的事件:
constructor(){
this.eventFormRefresh = (obj) => {
this.fetch(obj.isReset);
};
this.events.subscribe('form:refresh', this.eventFormRefresh);
}
ngOnDestroy(): void {
this.events.unsubscribe('form:refresh', this.eventFormRefresh);
}
Run Code Online (Sandbox Code Playgroud)
在子组件中,我通过发布 'form:refresh' 事件来激活刷新,如下所示:
this.events.publish('form:refresh');
Run Code Online (Sandbox Code Playgroud)
我将如何使用 angular observables 执行上述操作?