【发布时间】:2023-03-15 21:20:01
【问题描述】:
我刚刚开始学习这种离子/角度。所以,我有一个离子页面,它显示了通过服务获取的可观察项目列表。单击任何项目时,会通过将项目 ID 传递给它来打开一个弹出框。
此项目 ID 用于获取和显示弹出框内的项目详细信息。最后在弹出框内,有一个提交按钮,它将项目状态更新为 1。
MainPage.html
<div *ngFor="let bill of Bills$ | async">
<ion-label>{{bill.Name}}</ion-label>
{{bill.Description}}
<ion-toolbar>
<ion-buttons slot="start">
<ion-button (click)="openBill(bill.Id)">Draft Bill</ion-button>
</ion-buttons>
</ion-toolbar>
</div>
MainPage.component.ts
Bills$: Observable<Bill[]>;
openBill(ev:any){
console.log("Bill Id: "+ev);
this.presentPopover(ev);
}
async presentPopover(ev: any) {
const popover = await this.popoverController.create({
component: DraftbillPage,
componentProps: {
"BillId": ev
},
cssClass: 'my-custom-class',
event: ev,
translucent: true
});
return await popover.present();
}
ngOnInit() {
this.getBills();
}
getBills() {
this.Bills$ = this.userService.getBills();
}
用户服务.ts
export class UserService {
user: User;
Bills$: Observable<Bill[]>;
constructor() {
this.user = new User();
this.user.Bills = Bills;
this.Bills$ = of(this.user.Bills);
}
//Method called through popover update item status from 0 to 1
DraftBill(Id: number) {
this.user.Bills.filter(b => b.Id == Id)[0].Status = 1;
}
//Method called through main page to fetch list of items with status 0
getBills(): Observable<Bill[]> {
return this.Bills$.pipe(
map(bills => bills.filter(b => b.Status == 0))
);
}
//Method called through popover to item details
getBill(Id: number): Observable<Bill> {
return this.Bills$.pipe(
map(bills => bills.filter(b => b.Id == Id)[0])
);
}
}
问题是我在主页中的列表在更改项目状态后没有更新。我想在主页更新我的列表,只有状态为 0 的项目。我不确定我的方法是否正确。
【问题讨论】: