0

I'm creating an ion-modal dialog, and the close button calls

this.modalCtrl.dismiss(my_data, 'close');

I added the 'close' string as a role because I've seen it in other parts of the code. It's optional, so I'm wondering, is that good practice? Is it just to comply to html roles? If that is only meant to pass some extra data back, I can't see what's so special about it and why I shouldn't just include it in 'my_data'.

Any thoughts?

1 Answers1

1

Role defines the way you closed the modal, for example, you may cancel the modal so you can make the role as cancel, or you may do some functionality and submit and close modal after submit so you make the role as submit, when you listen on the modal after closing it, based on the role you can do some functionality, for example if the role was cancel, you do nothing or show message for user, and if the role was submit you view data passed from modal to your view

Emad Abdou
  • 277
  • 1
  • 7
  • Ok, but why is it so special? In the code handling the return from the modal I can look inside resultData.data and I can add the role information in there. Is it the case that resultData.role is automatically handled by the ionic framework somehow? – Daneel79108 Aug 01 '20 at 17:08
  • I think it's not automatically handled, all what ionic know is that you closed the modal as the only way to close modal is ` this.modal.dismiss() ` , if you canceled the modal or you did some functionality you will use the same method, so role is important there – Emad Abdou Aug 01 '20 at 17:12
  • You may have other solution, for example you pass data anyway when you dismiss modal, if your data is empty that means you canceled the modal, if your data not empty that means you did some functionality and dismissed the modal – Emad Abdou Aug 01 '20 at 17:15