Estoy tratando de pasar objetos entre páginas en mi aplicación Ionic Angular. Desafortunadamente, no pude encontrar la manera de hacerlo todavía. El objeto se pasa a la página de "detalles" recién abierta una vez. Sin embargo, al volver a la página inicial de "inicio", los Objetos ya no se pasan.
¿Alguien tiene una idea de cómo arreglar eso?
Aquí está el código:
inicio.pagina.html
<ion-content> <div *ngIf="spaces"> <ion-item-sliding *ngFor="let space of spaces | async;"> <ion-item (click)="openspacedetailsPage(space)" routerDirection="forward" detail > <ion-icon name="ellipse-outline" start></ion-icon> <ion-label> {{ space.spaceName }} </ion-label> </ion-item> </ion-item-sliding> </div>home.page.ts
openspacedetailsPage(space) { this.dataService.setSpace(space); this.router.navigate(["tabs/space-details"]); }servicio.de.datos.ts
setSpace(space) { this.space = space; }espacio-detalles.page.ts
ngOnInit() { this.space = this.dataService.space; this.spaceName = this.space.spaceName } pageBack() { this.space = {}; this.userId = ""; this.spaceId = ""; this.spaceName = ""; this.dataService.setSpace(undefined); } }Podría usar QueryParms para lograr eso. home.page.ts
openspacedetailsPage(space) { this.dataService.setSpace(space); this.router.navigate(["tabs/space-details"],{queryParams: {space}}); }espacio-detalles.page.ts
import { ActivatedRoute } from '@angular/router'; constructor(private route: ActivatedRoute) { } ngOnInit() { this.route.queryParams .subscribe(params => { console.log(params); this.space = params.space; } ); }Esta es la forma de pasar el objeto utilizando el enfoque de parámetro de consulta. Para obtener información detallada, consulte el siguiente enlace.
Aquí está la solución:
espacio-detalles.page.ts
ionViewDidEnter() { this.space = this.dataService.space; this.spaceName = this.space.spaceName; }