How to create a modal with parameters?


#1

How to create a modal with parameters such as in the example https://github.com/driftyco/ionic2/blob/master/ionic/components/modal/test/basic/index.ts ?

I copied the code from class ModalPassParams and i have met error :

EXCEPTION: No provider for NavParams! (ModalPassParams -> NavParams);

i use “ionic-framework”: “2.0.0-alpha.35”.
Thx


#2

Hi. If you managed to do that, I need to do the same thing and I got the same error.
If someone have an answer…
Thanks.

EDIT : Ok, got a workaround.

https://github.com/driftyco/ionic2/issues/604

In you modal, you won’t use “NavParams”, but inject “Modal” again and access to it’s “_defaults” property… Kinda weird but it works.

import {NgFor} from 'angular2/angular2';
import {
  Page, Modal
}
from 'ionic/ionic';
import './search.scss';

@
Page({
  templateUrl: 'app/search/search.html',
  directives: [NgFor]
})
export class SearchModal {
  constructor(modal: Modal) {
  this.modal = modal;
  console.log(this.modal._defaults);
}

#3

Thanks Thiphariel , this answer is wel , thx


#4

Just for saying, it’s only working on 2.0.0-alpha.35, on 2.0.0-alpha.37 and newers, “navParams” works great on Modals.


#5

in latest version… in case you end up here like I did

let newItemPage = Modal.create(NewItemModal, {"user": this.authInfo});
this.navCtrl.present(newItemPage);

in constructor of the NewItemModal, the data comes through as navParams

constructor( public viewCtrl: ViewController, private _navParams: NavParams) {
    console.log("initialize NewItemModal")
    console.log(this._navParams.get("user"))
}

#6

Thanks, @aaronksaunders, :+1:, Exactly what I was looking for