ViewController no longer has dismiss method
See original GitHub issueBug Report
Ionic Info
Run ionic info
from a terminal/cmd prompt and paste the output below.
ionic (Ionic CLI) : 4.1.1
Ionic Framework : @ionic/angular 4.0.0-beta.5
@angular-devkit/core : 0.7.5
@angular-devkit/schematics : 0.7.5
@angular/cli : 6.1.5
@ionic/ng-toolkit : 1.0.7
@ionic/schematics-angular : 1.0.5
Cordova:
cordova (Cordova CLI) : 7.1.0
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (0 plugins total)
System:
Android SDK Tools : 26.1.1 (/Users/rc101077/Library/Android/sdk)
ios-deploy : 2.0.0
ios-sim : 7.0.0
NodeJS : v8.11.3 (/Users/rc101077/.nvm/versions/node/v8.11.3/bin/node)
npm : 6.2.0
OS : macOS High Sierra
Xcode : Xcode 9.4.1 Build version 9F2000
Describe the Bug
Trying to close a Modal in the same way as Ionic3. The dismiss
method on the ViewController
no longer exists.
Steps to Reproduce Steps to reproduce the behavior:
- Create a modal with
ModalController
- Grab the
ViewController
in your component’s constructer - Call
this.viewCtrl.dismiss
- On compile, the error shows that
dismiss
is not part ofViewController
Related Code
public async openReset(): Promise<void> {
const resetModal: HTMLIonModalElement = await this.modalController.create({
backdropDismiss: false,
component: ResetModalPage,
componentProps: {
foo: 'foo',
bar: 2
}
});
return await resetModal.present();
}
The modal presents fine. Inside the ResetModalPage
:
public constructor(private navParams: NavParams, private viewCtrl: ViewController) {
this.foo = this.navParams.data.foo;
this.bar = this.navParams.data.bar;
}
public cancel(): void {
this.viewCtrl.dismiss(); // Error is here
}
Expected Behavior
In Ionic3, this worked find and you could even pass data in the dismiss
which you could receive on the “outside” with onDidDismiss
.
Workaround
For now, I’m passing in the modal to the constructed component and calling it’s dismiss
method:
componentProps: {
getModal: (): HTMLIonModalElement => { return resetModal; },
foo: 'foo',
bar: 2
}
public cancel(): void {
this.getModal().dismiss();
}
but this seems hacky at best. I also tried calling dismiss
directly on the ModalController
and trying goBack()
on the NavController
, but neither worked.
I also noted that ViewController
no longer comes from @ionic/angular
but now @ionic/angular/dist/types/components/nav/view-controller
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
@russcarver Did you try calling
this.modalCtrl.dismiss()
within the modal component itself (instead of the component where you launched the modal) ?Issue moved to: https://github.com/ionic-team/ionic-v3/issues/678