Modal component. Constructor data

Hello,

I am a new user on the Ionic community. At the moment, I am creating a little demo application with Ionic2 and today I have found a problem which I don´t know how to resolve. I neet to understand the structure of modal components.

https://github.com/driftyco/ionic/blob/2.0/src/components/modal/modal.ts

If you access to modal.ts you can see that constructor receives objects and appends into data object the componentType and ModalOptions.

constructor(componentType: any, data: any = {}, opts: ModalOptions = {}) {
data.componentType = componentType;
opts.showBackdrop = isPresent(opts.showBackdrop) ? !!opts.showBackdrop : true;
opts.enableBackdropDismiss = isPresent(opts.enableBackdropDismiss) ? !!opts.enableBackdropDismiss : true;
data.opts = opts;

super(ModalCmp, data);
this.isOverlay = true;
this.usePortal = true;

}

As a result I understand that data object is corrupted because it adds two new properties that actually it doesn´t need. For example, if I would want to persist the object I needed to clone the object and delete the extra properties or to delete into data object (params ) the extra properties.

Is this the usually work or is an issue?​

Thanks and best regards

I’m experiencing exactly the same thing. Looks like you never got an answer? I’m just cloning my data into an anonymous input object with Object.assign({}, realObject) to pass to the modal, then doing it in reverse (Object.assign(realObject, modalData)) to extract the changes onDidDismiss. Kind of ugly IMO, but seems to work.

Why are you trying to link the data object that is coming into the modal to the one that comes out in onDidDismiss()? They seem like totally unrelated entities to me.