Passing data to a modal

Asked

Viewed 710 times

0

I’m trying to pass data to a modal. I believe I got the first part, because on Chrome’s console I see that I received this data, but I don’t know what’s wrong, that I’m not being able to see them on the screen.

Home Html

 <button ion-button small class="button-select" (click)="openFiltrosModal()">Filtros</button>

Home TS

export class HomePage implements OnInit {
regioes: Regiao[];

constructor(public modalCtrl: ModalController, private nav: NavController, 
private videoPlayer: VideoPlayer, private payPal: PayPal, public viewCtrl: 
ViewController,public navCtrl: NavController, public navParams: NavParams, 
public db: DatabaseProvider, private toastCtrl: ToastController)

 openFiltrosModal() {
this.openModal('FiltrosModalPage');
}
openModal(pageName) {

this.modalCtrl.create(pageName, {'val': this.regioes}, { cssClass: 'inset- 
modal' })
              .present();
}

MODAL TS

import { Component } from '@angular/core';
import { NavParams, NavController, ViewController, IonicPage } from 'ionic- 
angular';
import { Regiao } from '../../models/regiao';

@IonicPage()
@Component({
selector: 'page-filtros-modal',
templateUrl: 'filtros-modal.html'
})
export class FiltrosModalPage {
regioes: Regiao;
myParam: string;

constructor(public navParams: NavParams, public viewCtrl: ViewController) {
console.log(navParams.get('val'));
this.myParam = navParams.get('myParam');
}

dismiss() {
this.viewCtrl.dismiss();
}

}

MODAL HTML

  <ion-select interface="popover" (ionChange)="selecionaregiao($event)" 
  [(ngModel)]="regiao">
  <ion-option *ngFor="let regiao of regioes" [value]="regiao.id"> 
  {{regiao.nom_regiao}}</ion-option>
  </ion-select>

img

Can someone help me with this? I don’t know if I’m doing it wrong or forgetting something

  • shows the console error

  • @Juliohenrique I do not get any error when opening Modal. only in the console I receive the data as posted in the image above. But when I click Select on the page, there is no result. But if I just put: {{regiao.nom_regiao}} which is what I use on the Home page and it works, then give the error: ERROR Typeerror: Cannot read Property 'nom_regiao' of Undefined at Object.Val [as updateRenderer] (Filtrosmodalpage.html:23) at Object.debugUpdateRenderer [the updateRenderer]

  • Where you initialize "regions"?

1 answer

2


HTML is searching for the variable regioes and not the myParams. In the constructor, change this.myParam = navParams.get('myParam'); for this.regioes = navParams.get('myParam');.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.