Hi !
I’m trying to pass data of cards to modals. i have a list of cards, and I want to retrieve ID’s of this cards in a modal when I click on here.
I can pass static data with this :
export class Tab1Page {
interventions: Observable<any>;
dataReturned: any;
constructor( private httpClient: HttpClient, public modalController: ModalController) {
this.interventions = this.httpClient.get('http://***.php');
}
async openModal() {
const modal = await this.modalController.create({
component: ModalPage,
componentProps: {
paramID: '2',
paramTitle: 'Test Title',
}
});
modal.onDidDismiss().then((dataReturned) => {
if (dataReturned !== null) {
this.dataReturned = dataReturned.data;
}
});
return await modal.present();
}
}
But how can I pass “dynamic” data ?
My modal.page.ts :
export class ModalPage implements OnInit {
modalTitle: string;
modelId: number;
constructor(
private modalController: ModalController,
private navParams: NavParams
) { }
ngOnInit() {
console.table(this.navParams);
this.modelId = this.navParams.data.paramID;
this.modalTitle = this.navParams.data.paramTitle;
console.log(this.modelId);
}
async closeModal() {
const onClosedData: string = "Wrapped Up!";
await this.modalController.dismiss(onClosedData);
}
}
Before, I was using this, but I want to change this by modal :
<ion-card class="inter-card open-{{intervention.statut}}" ion-item *ngFor="let intervention of (interventions | async)?.interventions" [routerLink]="'/details/' + intervention.id" routerDirection="forward" >
And on my ts :
ngOnInit() {
this.myId = this.activatedRoute.snapshot.paramMap.get('myid');
}
Thank you !