Reputation: 179
I have one .ts file for model. I want to execute some code when this model is dismissed(from model file itself).
All examples are about onDidDismiss()
method which is written in model caller .ts file.I mean i have some db listeners in my model .ts file.
What i am trying to do is unsubscribe them when user dismisses the model window by clicking outside of model window.
Upvotes: 1
Views: 1367
Reputation: 483
You can publish event inside of onDidDismiss()
and subscribe event from where you want.
Your modal page ts file:
import { ....., Events } from 'ionic-angular';
constructor(....,public events:Events){.....}
modal.onDidDismiss(()=>{
this.events.publish("modal:dismissed","data what you want to publish",Date.now());
})
subscription from anywhere:
import and inject again Events
like in your modal ts file then;
this.events.subscribe('modal:dismissed', (value, publishTime) => {
//enter your code here
});
Upvotes: 0
Reputation: 8351
You can use below method in your Model page :
dismiss() {
this.viewCtrl.dismiss();
}
and in this method you can write your code.
Ref Link : https://github.com/ionic-team/ionic/tree/v3/demos/src/modal
Ionic Ref : https://ionicframework.com/docs/api/components/modal/ModalController/
Hope this will helps!
Upvotes: 2